From 50cbf00e8f4aa3265dd3b288b489e5d87f40f48e Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 16 Jun 2024 02:23:01 +0200 Subject: [PATCH] feat(biome): add lint and check command --- README.md | 4 +++- schemas/v0.1.1/mdsf.schema.json | 10 ++++++++++ src/formatters/biome.rs | 30 +++++++++++++++++++++++++----- src/formatters/mod.rs | 14 +++++++++++++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f3018100..b940a2e6 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ mdsf init -`mdsf` currently supports 128 tools. +`mdsf` currently supports 130 tools. | Formatter | Description | | ------------------ | ---------------------------------------------------------------------------------------------------------------------- | @@ -118,6 +118,8 @@ mdsf init | beautysh | [https://pypi.org/project/beautysh/](https://pypi.org/project/beautysh/) | | bicep_format | [https://github.com/Azure/bicep](https://github.com/Azure/bicep) | | biome | [https://biomejs.dev](https://biomejs.dev) | +| biome_check | [https://biomejs.dev](https://biomejs.dev) | +| biome_lint | [https://biomejs.dev](https://biomejs.dev) | | black | [https://github.com/psf/black](https://github.com/psf/black) | | blade-formatter | [https://github.com/shufo/blade-formatter](https://github.com/shufo/blade-formatter) | | blue | [https://blue.readthedocs.io/en/latest/](https://blue.readthedocs.io/en/latest/) | diff --git a/schemas/v0.1.1/mdsf.schema.json b/schemas/v0.1.1/mdsf.schema.json index e1ded1d2..43f1f022 100644 --- a/schemas/v0.1.1/mdsf.schema.json +++ b/schemas/v0.1.1/mdsf.schema.json @@ -99,6 +99,16 @@ "type": "string", "enum": ["biome"] }, + { + "description": "https://biomejs.dev", + "type": "string", + "enum": ["biome_lint"] + }, + { + "description": "https://biomejs.dev", + "type": "string", + "enum": ["biome_check"] + }, { "description": "https://github.com/psf/black", "type": "string", diff --git a/src/formatters/biome.rs b/src/formatters/biome.rs index fe4487be..b7898b32 100644 --- a/src/formatters/biome.rs +++ b/src/formatters/biome.rs @@ -2,7 +2,7 @@ use super::execute_command; use crate::{error::MdsfError, runners::setup_npm_script}; #[inline] -pub fn run(snippet_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { +pub fn run_format(snippet_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { // NOTE: the biome docs recommend running biome using npx, and not directly let mut cmd = setup_npm_script("@biomejs/biome"); @@ -11,10 +11,30 @@ pub fn run(snippet_path: &std::path::Path) -> Result<(bool, Option), Mds execute_command(&mut cmd, snippet_path) } +#[inline] +pub fn run_lint(snippet_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + // NOTE: the biome docs recommend running biome using npx, and not directly + let mut cmd = setup_npm_script("@biomejs/biome"); + + cmd.arg("lint").arg("--write").arg(snippet_path); + + execute_command(&mut cmd, snippet_path) +} + +#[inline] +pub fn run_check(snippet_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + // NOTE: the biome docs recommend running biome using npx, and not directly + let mut cmd = setup_npm_script("@biomejs/biome"); + + cmd.arg("check").arg("--write").arg(snippet_path); + + execute_command(&mut cmd, snippet_path) +} + #[cfg(test)] mod test_biome { use crate::{ - formatters::{biome::run, setup_snippet}, + formatters::{biome::run_format, setup_snippet}, generated::language_to_ext, }; @@ -40,7 +60,7 @@ mod test_biome { let snippet = setup_snippet(input, &language_to_ext("json")).expect("it to create a snippet file"); - let output = run(snippet.path()) + let output = run_format(snippet.path()) .expect("it to be successful") .1 .expect("it to be some"); @@ -67,7 +87,7 @@ mod test_biome { let snippet = setup_snippet(input, &language_to_ext("javascript")) .expect("it to create a snippet file"); - let output = run(snippet.path()) + let output = run_format(snippet.path()) .expect("it to be successful") .1 .expect("it to be some"); @@ -97,7 +117,7 @@ number> let snippet = setup_snippet(input, &language_to_ext("typescript")) .expect("it to create a snippet file"); - let output = run(snippet.path()) + let output = run_format(snippet.path()) .expect("it to be successful") .1 .expect("it to be some"); diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index c5c427b0..72e9ee54 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -301,6 +301,14 @@ pub enum Tooling { #[serde(rename = "biome")] Biome, + #[doc = "https://biomejs.dev"] + #[serde(rename = "biome_lint")] + BiomeLint, + + #[doc = "https://biomejs.dev"] + #[serde(rename = "biome_check")] + BiomeCheck, + #[doc = "https://github.com/psf/black"] #[serde(rename = "black")] Black, @@ -792,7 +800,9 @@ impl Tooling { Self::Autopep8 => autopep8::run(snippet_path), Self::Beautysh => beautysh::run(snippet_path), Self::BicepFormat => bicep_format::run(snippet_path), - Self::Biome => biome::run(snippet_path), + Self::Biome => biome::run_format(snippet_path), + Self::BiomeCheck => biome::run_check(snippet_path), + Self::BiomeLint => biome::run_lint(snippet_path), Self::Black => black::run(snippet_path), Self::BladeFormatter => blade_formatter::run(snippet_path), Self::Blue => blue::run(snippet_path), @@ -930,6 +940,8 @@ impl core::fmt::Display for Tooling { Self::Beautysh => write!(f, "beautysh"), Self::BicepFormat => write!(f, "bicep_format"), Self::Biome => write!(f, "biome"), + Self::BiomeCheck => write!(f, "biome_check"), + Self::BiomeLint => write!(f, "biome_lint"), Self::Black => write!(f, "black"), Self::BladeFormatter => write!(f, "blade-formatter"), Self::Blue => write!(f, "blue"),