Skip to content

Commit

Permalink
feat(biome): add lint and check command
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jun 16, 2024
1 parent 6953484 commit 50cbf00
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mdsf init
<!-- START_SECTION:supported-languages -->

`mdsf` currently supports 128 tools.
`mdsf` currently supports 130 tools.

| Formatter | Description |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -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/) |
Expand Down
10 changes: 10 additions & 0 deletions schemas/v0.1.1/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 25 additions & 5 deletions src/formatters/biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>), MdsfError> {
pub fn run_format(snippet_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
// NOTE: the biome docs recommend running biome using npx, and not directly
let mut cmd = setup_npm_script("@biomejs/biome");

Expand All @@ -11,10 +11,30 @@ pub fn run(snippet_path: &std::path::Path) -> Result<(bool, Option<String>), Mds
execute_command(&mut cmd, snippet_path)
}

#[inline]
pub fn run_lint(snippet_path: &std::path::Path) -> Result<(bool, Option<String>), 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<String>), 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,
};

Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
14 changes: 13 additions & 1 deletion src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 50cbf00

Please sign in to comment.