diff --git a/README.md b/README.md index 15e54c0c..0278f250 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ mdsf init -`mdsf` currently supports 140 tools. +`mdsf` currently supports 141 tools. | Formatter | Description | | ------------------ | ---------------------------------------------------------------------------------------------------------------------- | @@ -172,6 +172,7 @@ mdsf init | goimports-reviser | [/~https://github.com/incu6us/goimports-reviser](/~https://github.com/incu6us/goimports-reviser) | | golines | [/~https://github.com/segmentio/golines](/~https://github.com/segmentio/golines) | | google-java-format | [/~https://github.com/google/google-java-format](/~https://github.com/google/google-java-format) | +| grain_format | [https://grain-lang.org](https://grain-lang.org) | | haml-lint | [/~https://github.com/sds/haml-lint](/~https://github.com/sds/haml-lint) | | hindent | [https://hackage.haskell.org/package/hindent](https://hackage.haskell.org/package/hindent) | | htmlbeautifier | [/~https://github.com/threedaymonk/htmlbeautifier](/~https://github.com/threedaymonk/htmlbeautifier) | diff --git a/mdsf.json b/mdsf.json index 6d51870b..3705b3b4 100644 --- a/mdsf.json +++ b/mdsf.json @@ -14,11 +14,13 @@ "elixir": "mix_format", "elm": "elm-format", "erlang": [["erlfmt", "efmt"]], + "gleam": "gleam_format", "go": [ ["gci", "goimports-reviser", "goimports"], ["gofumpt", "gofmt", "crlfmt"] ], + "grain": "grain_format", "haskell": [["fourmolu", "ormolu", "hindent", "stylish-haskell"]], "html": [["prettier", "djlint"]], "java": [["google-java-format", "clang-format"]], diff --git a/schemas/v0.1.2/mdsf.schema.json b/schemas/v0.1.2/mdsf.schema.json index fad6cd02..65bc0a5c 100644 --- a/schemas/v0.1.2/mdsf.schema.json +++ b/schemas/v0.1.2/mdsf.schema.json @@ -369,6 +369,11 @@ "type": "string", "enum": ["google-java-format"] }, + { + "description": "https://grain-lang.org", + "type": "string", + "enum": ["grain_format"] + }, { "description": "/~https://github.com/sds/haml-lint", "type": "string", diff --git a/src/formatters/grain.rs b/src/formatters/grain.rs new file mode 100644 index 00000000..94ab1143 --- /dev/null +++ b/src/formatters/grain.rs @@ -0,0 +1,11 @@ +use super::execute_command; +use crate::error::MdsfError; + +#[inline] +pub fn run_format(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let mut cmd = std::process::Command::new("grain"); + + cmd.arg("format").arg(file_path).arg("-o").arg(file_path); + + execute_command(&mut cmd, file_path) +} diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index f22249f0..c85e3ca6 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -73,6 +73,7 @@ mod goimports; mod goimports_reviser; mod golines; mod google_java_format; +mod grain; mod haml_lint; mod hindent; mod htmlbeautifier; @@ -523,6 +524,10 @@ pub enum Tooling { #[serde(rename = "google-java-format")] GoogleJavaFormat, + #[doc = "https://grain-lang.org"] + #[serde(rename = "grain_format")] + GrainFormat, + #[doc = "/~https://github.com/sds/haml-lint"] #[serde(rename = "haml-lint")] HamlLint, @@ -901,6 +906,7 @@ impl Tooling { Self::GoImportsReviser => goimports_reviser::run(snippet_path), Self::GoLines => golines::run(snippet_path), Self::GoogleJavaFormat => google_java_format::run(snippet_path), + Self::GrainFormat => grain::run_format(snippet_path), Self::HIndent => hindent::run(snippet_path), Self::HamlLint => haml_lint::run(snippet_path), Self::Htmlbeautifier => htmlbeautifier::run(snippet_path), @@ -1050,6 +1056,7 @@ impl core::fmt::Display for Tooling { Self::GoImportsReviser => write!(f, "goimports-reviser"), Self::GoLines => write!(f, "golines"), Self::GoogleJavaFormat => write!(f, "google-java-format"), + Self::GrainFormat => write!(f, "grain_format"), Self::HIndent => write!(f, "hundent"), Self::HamlLint => write!(f, "haml-lint"), Self::Htmlbeautifier => write!(f, "htmlbeautifier"), diff --git a/tests/grain.md b/tests/grain.md new file mode 100644 index 00000000..3857ca70 --- /dev/null +++ b/tests/grain.md @@ -0,0 +1,26 @@ +```grain + + + + + + + + + + + + + + + + + + + +module Hello + +print("hello world" ) + + +```