From 32d93395e08d3ecca9e54a0af719014a8afbd36d Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sat, 26 Oct 2024 21:32:38 +0200 Subject: [PATCH] feat: support shellharden --- CHANGELOG.md | 1 + README.md | 3 ++- mdsf/src/tools/mod.rs | 7 +++++ mdsf/src/tools/shellharden.rs | 36 ++++++++++++++++++++++++++ schemas/v0.2.7/mdsf.schema.json | 5 ++++ tools/djlint/plugin.json | 2 +- tools/easy-coding-standard/plugin.json | 2 +- tools/joker/plugin.json | 2 +- tools/shellharden/plugin.json | 17 ++++++++++++ 9 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 mdsf/src/tools/shellharden.rs create mode 100644 tools/shellharden/plugin.json diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7c8041..abf41fd0 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 shellharden [`#504`](https://github.com/hougesen/mdsf/pull/504) - feat: support reorder-python-imports [`#503`](https://github.com/hougesen/mdsf/pull/503) - feat: support reformat-gherkin [`#502`](https://github.com/hougesen/mdsf/pull/502) - deps(clap): upgrade to 4.5.20 [`#501`](https://github.com/hougesen/mdsf/pull/501) diff --git a/README.md b/README.md index 1b76af01..6a551923 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`mdsf` currently supports 194 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 +`mdsf` currently supports 195 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 | Name | Command | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -337,6 +337,7 @@ mdsf init | `rustywind` | `rustywind --write PATH` | | `scalafmt` | `scalafmt --quiet --mode any PATH` | | `scalariform` | `scalariform PATH` | +| `shellharden` | `shellharden --transform --replace PATH` | | `shfmt` | `shfmt --write PATH` | | `sleek` | `sleek PATH` | | `smlfmt` | `smlfmt --force PATH` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 8f04ea5e..6d6c1303 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -147,6 +147,7 @@ pub mod rustfmt; pub mod rustywind; pub mod scalafmt; pub mod scalariform; +pub mod shellharden; pub mod shfmt; pub mod sleek; pub mod smlfmt; @@ -793,6 +794,10 @@ pub enum Tooling { /// `scalariform $PATH` Scalariform, + #[serde(rename = "shellharden")] + /// `shellharden --transform --replace $PATH` + Shellharden, + #[serde(rename = "shfmt")] /// `shfmt --write $PATH` Shfmt, @@ -1131,6 +1136,7 @@ impl Tooling { Self::Rustywind => rustywind::run(snippet_path), Self::Scalafmt => scalafmt::run(snippet_path), Self::Scalariform => scalariform::run(snippet_path), + Self::Shellharden => shellharden::run(snippet_path), Self::Shfmt => shfmt::run(snippet_path), Self::Sleek => sleek::run(snippet_path), Self::Smlfmt => smlfmt::run(snippet_path), @@ -1334,6 +1340,7 @@ impl AsRef for Tooling { Self::Rustywind => "rustywind", Self::Scalafmt => "scalafmt", Self::Scalariform => "scalariform", + Self::Shellharden => "shellharden", Self::Shfmt => "shfmt", Self::Sleek => "sleek", Self::Smlfmt => "smlfmt", diff --git a/mdsf/src/tools/shellharden.rs b/mdsf/src/tools/shellharden.rs new file mode 100644 index 00000000..32e3b72b --- /dev/null +++ b/mdsf/src/tools/shellharden.rs @@ -0,0 +1,36 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_shellharden_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("--transform"); + cmd.arg("--replace"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("shellharden")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_shellharden_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_shellharden {} diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index c057ff35..a518d3ae 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -803,6 +803,11 @@ "type": "string", "enum": ["scalariform"] }, + { + "description": "`shellharden --transform --replace $PATH`", + "type": "string", + "enum": ["shellharden"] + }, { "description": "`shfmt --write $PATH`", "type": "string", diff --git a/tools/djlint/plugin.json b/tools/djlint/plugin.json index f7cb74f8..a8599383 100644 --- a/tools/djlint/plugin.json +++ b/tools/djlint/plugin.json @@ -1,7 +1,7 @@ { "$schema": "../tool.schema.json", "binary": "djlint", - "categories": ["linter", "formatter"], + "categories": ["formatter", "linter"], "commands": { "": ["$PATH", "--reformat"] }, diff --git a/tools/easy-coding-standard/plugin.json b/tools/easy-coding-standard/plugin.json index b91b828e..d79a20ae 100644 --- a/tools/easy-coding-standard/plugin.json +++ b/tools/easy-coding-standard/plugin.json @@ -1,7 +1,7 @@ { "$schema": "../tool.schema.json", "binary": "ecs", - "categories": ["linter", "formatter"], + "categories": ["formatter", "linter"], "commands": { "": ["check", "$PATH", "--fix", "--no-interaction"] }, diff --git a/tools/joker/plugin.json b/tools/joker/plugin.json index 11a2bde0..a12ab164 100644 --- a/tools/joker/plugin.json +++ b/tools/joker/plugin.json @@ -1,7 +1,7 @@ { "$schema": "../tool.schema.json", "binary": "joker", - "categories": ["linter", "formatter"], + "categories": ["formatter", "linter"], "commands": { "": ["--format", "--write", "$PATH"] }, diff --git a/tools/shellharden/plugin.json b/tools/shellharden/plugin.json new file mode 100644 index 00000000..40f609d2 --- /dev/null +++ b/tools/shellharden/plugin.json @@ -0,0 +1,17 @@ +{ + "$schema": "../tool.schema.json", + + "binary": "shellharden", + + "commands": { + "": ["--transform", "--replace", "$PATH"] + }, + "languages": ["bash", "shell"], + "categories": ["linter"], + "description": "The corrective bash syntax highlighter", + "homepage": "https://github.com/anordal/shellharden", + "name": null, + "tests": [], + "npm": null, + "php": null +}