From 4883e3159dfe83f3c206924f976379aee0753ac7 Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Thu, 20 Jun 2024 17:30:05 +0200 Subject: [PATCH] feat(nickel): support nickel format (#317) --- README.md | 3 ++- schemas/v0.1.2/mdsf.schema.json | 5 +++++ src/formatters/mod.rs | 7 +++++++ src/formatters/nickel.rs | 11 +++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/formatters/nickel.rs diff --git a/README.md b/README.md index 0c551ffb..9aca3cce 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ mdsf init -`mdsf` currently supports 138 tools. +`mdsf` currently supports 139 tools. | Formatter | Description | | ------------------ | ---------------------------------------------------------------------------------------------------------------------- | @@ -192,6 +192,7 @@ mdsf init | mdformat | [https://github.com/executablebooks/mdformat](https://github.com/executablebooks/mdformat) | | misspell | [https://github.com/client9/misspell/](https://github.com/client9/misspell/) | | mix_format | [https://hexdocs.pm/mix/main/Mix.Tasks.Format.html](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) | +| nickel_format | [https://nickel-lang.org](https://nickel-lang.org) | | nimpretty | [https://github.com/nim-lang/nim](https://github.com/nim-lang/nim) | | nixfmt | [https://github.com/serokell/nixfmt](https://github.com/serokell/nixfmt) | | nixpkgs-fmt | [https://github.com/nix-community/nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) | diff --git a/schemas/v0.1.2/mdsf.schema.json b/schemas/v0.1.2/mdsf.schema.json index 7175ec5a..ab4f547d 100644 --- a/schemas/v0.1.2/mdsf.schema.json +++ b/schemas/v0.1.2/mdsf.schema.json @@ -469,6 +469,11 @@ "type": "string", "enum": ["mix_format"] }, + { + "description": "https://nickel-lang.org", + "type": "string", + "enum": ["nickel_format"] + }, { "description": "https://github.com/nim-lang/nim", "type": "string", diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index 7f7d88fb..aea7f2f9 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -93,6 +93,7 @@ mod markuplint; mod mdformat; mod misspell; mod mix_format; +mod nickel; mod nimpretty; mod nixfmt; mod nixpkgs_fmt; @@ -601,6 +602,10 @@ pub enum Tooling { #[serde(rename = "mix_format")] MixFormat, + #[doc = "https://nickel-lang.org"] + #[serde(rename = "nickel_format")] + NickelFormat, + #[doc = "https://github.com/nim-lang/nim"] #[serde(rename = "nimpretty")] Nimpretty, @@ -911,6 +916,7 @@ impl Tooling { Self::MdFormat => mdformat::run(snippet_path), Self::Misspell => misspell::run(snippet_path), Self::MixFormat => mix_format::run(snippet_path), + Self::NickelFormat => nickel::run_format(snippet_path), Self::NicklockwoodSwiftFormat => swiftformat::run(snippet_path), Self::Nimpretty => nimpretty::run(snippet_path), Self::Nixfmt => nixfmt::run(snippet_path), @@ -1058,6 +1064,7 @@ impl core::fmt::Display for Tooling { Self::MdFormat => write!(f, "mdformat"), Self::Misspell => write!(f, "misspell"), Self::MixFormat => write!(f, "mix_format"), + Self::NickelFormat => write!(f, "nickel_format"), Self::NicklockwoodSwiftFormat => write!(f, "swiftformat"), Self::Nimpretty => write!(f, "nimpretty"), Self::Nixfmt => write!(f, "nixfmt"), diff --git a/src/formatters/nickel.rs b/src/formatters/nickel.rs new file mode 100644 index 00000000..4843de2d --- /dev/null +++ b/src/formatters/nickel.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("nickel"); + + cmd.arg("format").arg(file_path); + + execute_command(&mut cmd, file_path) +}