diff --git a/CHANGELOG.md b/CHANGELOG.md index 11ffb2d2..c14e42cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.2.7...HEAD) +- feat: support json5format [`#522`](https://github.com/hougesen/mdsf/pull/522) - feat: support kdoc-formatter [`#521`](https://github.com/hougesen/mdsf/pull/521) - feat: support djade [`#520`](https://github.com/hougesen/mdsf/pull/520) - feat: support tsqllint [`#519`](https://github.com/hougesen/mdsf/pull/519) diff --git a/README.md b/README.md index bb3195aa..92eb0356 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`mdsf` currently supports 212 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 +`mdsf` currently supports 213 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 | Name | Command | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -280,6 +280,7 @@ mdsf init | `isort` | `isort --quiet PATH` | | `joker` | `joker --format --write PATH` | | `js-beautify` | `js-beautify -r --type js -f PATH` | +| `json5format` | `json5format -r PATH` | | `jsona:format` | `jsona format PATH` | | `jsona:lint` | `jsona lint PATH` | | `jsonlint` | `jsonlint -i PATH` | diff --git a/mdsf/src/tools/json_5_format.rs b/mdsf/src/tools/json_5_format.rs new file mode 100644 index 00000000..4b22f09d --- /dev/null +++ b/mdsf/src/tools/json_5_format.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_json_5_format_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("-r"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("json5format")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_json_5_format_args(cmd.build(), file_path); + let execution_result = execute_command(cmd, file_path); + + if index == commands.len() - 1 { + return execution_result; + } + + if let Ok(r) = execution_result { + if !r.0 { + return Ok(r); + } + } + } + + Ok((true, None)) +} + +#[cfg(test)] +mod test_json_5_format {} diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 94713416..18cb287b 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -90,6 +90,7 @@ pub mod imba_fmt; pub mod isort; pub mod joker; pub mod js_beautify; +pub mod json_5_format; pub mod jsona_format; pub mod jsona_lint; pub mod jsonlint; @@ -583,6 +584,10 @@ pub enum Tooling { /// `js-beautify -r --type js -f $PATH` JsBeautify, + #[serde(rename = "json5format")] + /// `json5format -r $PATH` + Json5Format, + #[serde(rename = "jsona:format")] /// `jsona format $PATH` JsonaFormat, @@ -1164,6 +1169,7 @@ impl Tooling { Self::Isort => isort::run(snippet_path), Self::Joker => joker::run(snippet_path), Self::JsBeautify => js_beautify::run(snippet_path), + Self::Json5Format => json_5_format::run(snippet_path), Self::JsonaFormat => jsona_format::run(snippet_path), Self::JsonaLint => jsona_lint::run(snippet_path), Self::Jsonlint => jsonlint::run(snippet_path), @@ -1385,6 +1391,7 @@ impl AsRef for Tooling { Self::Isort => "isort", Self::Joker => "joker", Self::JsBeautify => "js_beautify", + Self::Json5Format => "json_5_format", Self::JsonaFormat => "jsona_format", Self::JsonaLint => "jsona_lint", Self::Jsonlint => "jsonlint", diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index 8e7bd957..5dba378e 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -518,6 +518,11 @@ "type": "string", "enum": ["js-beautify"] }, + { + "description": "`json5format -r $PATH`", + "type": "string", + "enum": ["json5format"] + }, { "description": "`jsona format $PATH`", "type": "string", diff --git a/tools/json5format/plugin.json b/tools/json5format/plugin.json new file mode 100644 index 00000000..7257490b --- /dev/null +++ b/tools/json5format/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "json5format", + "categories": ["formatter"], + "commands": { + "": ["-r", "$PATH"] + }, + "description": "JSON5 (a.k.a., \"JSON for Humans\") formatter that preserves contextual comments", + "homepage": "https://github.com/google/json5format", + "languages": ["json", "json5"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}