diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea137d..5ba9536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.2.7...HEAD) +- feat: support hlint [`#507`](https://github.com/hougesen/mdsf/pull/507) +- feat: support bslint [`#506`](https://github.com/hougesen/mdsf/pull/506) - feat: support terragrunt hclfmt [`#505`](https://github.com/hougesen/mdsf/pull/505) - feat: support shellharden [`#504`](https://github.com/hougesen/mdsf/pull/504) - feat: support reorder-python-imports [`#503`](https://github.com/hougesen/mdsf/pull/503) diff --git a/README.md b/README.md index fa16ebb..ff81616 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`mdsf` currently supports 197 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 +`mdsf` currently supports 198 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 | Name | Command | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -268,6 +268,7 @@ mdsf init | `haml-lint` | `haml-lint --auto-correct PATH` | | `hfmt` | `hfmt -w PATH` | | `hindent` | `hindent PATH` | +| `hlint` | `hlint --refactor -i PATH` | | `html-beautify` | `html-beautify -r --type html -f PATH` | | `htmlbeautifier` | `htmlbeautifier PATH` | | `imba:fmt` | `imba fmt -f PATH` | diff --git a/mdsf/src/tools/hlint.rs b/mdsf/src/tools/hlint.rs new file mode 100644 index 0000000..c545107 --- /dev/null +++ b/mdsf/src/tools/hlint.rs @@ -0,0 +1,36 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_hlint_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("--refactor"); + cmd.arg("-i"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("hlint")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_hlint_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_hlint {} diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index d248e68..e4321c2 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -78,6 +78,7 @@ pub mod grain_format; pub mod haml_lint; pub mod hfmt; pub mod hindent; +pub mod hlint; pub mod html_beautify; pub mod htmlbeautifier; pub mod imba_fmt; @@ -520,6 +521,10 @@ pub enum Tooling { /// `hindent $PATH` Hindent, + #[serde(rename = "hlint")] + /// `hlint --refactor -i $PATH` + Hlint, + #[serde(rename = "html-beautify")] /// `html-beautify -r --type html -f $PATH` HtmlBeautify, @@ -1077,6 +1082,7 @@ impl Tooling { Self::HamlLint => haml_lint::run(snippet_path), Self::Hfmt => hfmt::run(snippet_path), Self::Hindent => hindent::run(snippet_path), + Self::Hlint => hlint::run(snippet_path), Self::HtmlBeautify => html_beautify::run(snippet_path), Self::Htmlbeautifier => htmlbeautifier::run(snippet_path), Self::ImbaFmt => imba_fmt::run(snippet_path), @@ -1283,6 +1289,7 @@ impl AsRef for Tooling { Self::HamlLint => "haml_lint", Self::Hfmt => "hfmt", Self::Hindent => "hindent", + Self::Hlint => "hlint", Self::HtmlBeautify => "html_beautify", Self::Htmlbeautifier => "htmlbeautifier", Self::ImbaFmt => "imba_fmt", diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index 23b5a60..b0fdb46 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -458,6 +458,11 @@ "type": "string", "enum": ["hindent"] }, + { + "description": "`hlint --refactor -i $PATH`", + "type": "string", + "enum": ["hlint"] + }, { "description": "`html-beautify -r --type html -f $PATH`", "type": "string", diff --git a/tools/hlint/plugin.json b/tools/hlint/plugin.json new file mode 100644 index 0000000..faa2ff4 --- /dev/null +++ b/tools/hlint/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "hlint", + "categories": ["linter"], + "commands": { + "": ["--refactor", "-i", "$PATH"] + }, + "description": "Haskell source code suggestions", + "homepage": "https://github.com/ndmitchell/hlint", + "languages": ["haskell"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}