Skip to content

Commit

Permalink
feat(grain): support grain format (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jun 20, 2024
1 parent de16f17 commit 7dfcc09
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
3 changes: 2 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 140 tools.
`mdsf` currently supports 141 tools.

| Formatter | Description |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -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) |
Expand Down
2 changes: 2 additions & 0 deletions mdsf.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]],
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.1.2/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions src/formatters/grain.rs
Original file line number Diff line number Diff line change
@@ -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<String>), 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)
}
7 changes: 7 additions & 0 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mod goimports;
mod goimports_reviser;
mod golines;
mod google_java_format;
mod grain;
mod haml_lint;
mod hindent;
mod htmlbeautifier;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand Down
26 changes: 26 additions & 0 deletions tests/grain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
```grain
module Hello
print("hello world" )
```

0 comments on commit 7dfcc09

Please sign in to comment.