From 02a85f0db8e1b6e4fa3f32423cbaa0fabf1fbdf6 Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 12 Jan 2025 19:18:53 +0100 Subject: [PATCH] feat: add support for salt-lint (#601) --- CHANGELOG.md | 1 + README.md | 3 ++- mdsf/src/tools/mod.rs | 7 ++++++ mdsf/src/tools/salt_lint.rs | 34 +++++++++++++++++++++++++++++ schemas/v0.3.3-dev/mdsf.schema.json | 5 +++++ tools/salt-lint/plugin.json | 15 +++++++++++++ 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 mdsf/src/tools/salt_lint.rs create mode 100644 tools/salt-lint/plugin.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d06abaa5..50fc59b2 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.3.2...HEAD) +- feat: add support for salt-lint [`#601`](https://github.com/hougesen/mdsf/pull/601) - feat: add support for regal [`#600`](https://github.com/hougesen/mdsf/pull/600) - feat: add support for quick-lint-js [`#599`](https://github.com/hougesen/mdsf/pull/599) - feat: add support for oelint-adv [`#598`](https://github.com/hougesen/mdsf/pull/598) diff --git a/README.md b/README.md index 50a1ece9..6a9fe20e 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`mdsf` currently supports 232 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 233 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -395,6 +395,7 @@ mdsf init | [rune](https://github.com/rune-rs/rune) | Tools for the Rune programming language | `formatter` | `rune` | | [rustfmt](https://github.com/rust-lang/rustfmt) | The official code formatter for Rust | `formatter` | `rust` | | [rustywind](https://github.com/avencera/rustywind) | CLI for organizing Tailwind CSS classes | `formatter` | `html` | +| [salt-lint](https://github.com/warpnet/salt-lint) | A command-line utility that checks for best practices in SaltStack | `linter` | `salt` | | [scalafmt](https://github.com/scalameta/scalafmt) | Code formatter for Scala | `formatter` | `scala` | | [scalariform](https://github.com/scala-ide/scalariform) | Scala source code formatter | `formatter` | `scala` | | [shellharden](https://github.com/anordal/shellharden) | The corrective bash syntax highlighter | `linter` | `bash`, `shell` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 70cb7232..10805583 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -184,6 +184,7 @@ pub mod rufo; pub mod rune_fmt; pub mod rustfmt; pub mod rustywind; +pub mod salt_lint; pub mod scalafmt; pub mod scalariform; pub mod shellharden; @@ -990,6 +991,10 @@ pub enum Tooling { /// `rustywind --write $PATH` Rustywind, + #[serde(rename = "salt-lint")] + /// `salt-lint $PATH` + SaltLint, + #[serde(rename = "scalafmt")] /// `scalafmt --quiet --mode any $PATH` Scalafmt, @@ -1413,6 +1418,7 @@ impl Tooling { Self::RuneFmt => rune_fmt::run(snippet_path), Self::Rustfmt => rustfmt::run(snippet_path), Self::Rustywind => rustywind::run(snippet_path), + Self::SaltLint => salt_lint::run(snippet_path), Self::Scalafmt => scalafmt::run(snippet_path), Self::Scalariform => scalariform::run(snippet_path), Self::Shellharden => shellharden::run(snippet_path), @@ -1665,6 +1671,7 @@ impl AsRef for Tooling { Self::RuneFmt => "rune_fmt", Self::Rustfmt => "rustfmt", Self::Rustywind => "rustywind", + Self::SaltLint => "salt_lint", Self::Scalafmt => "scalafmt", Self::Scalariform => "scalariform", Self::Shellharden => "shellharden", diff --git a/mdsf/src/tools/salt_lint.rs b/mdsf/src/tools/salt_lint.rs new file mode 100644 index 00000000..b72ee010 --- /dev/null +++ b/mdsf/src/tools/salt_lint.rs @@ -0,0 +1,34 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_salt_lint_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("salt-lint")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_salt_lint_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_salt_lint {} diff --git a/schemas/v0.3.3-dev/mdsf.schema.json b/schemas/v0.3.3-dev/mdsf.schema.json index d5f509dc..96d45ea9 100644 --- a/schemas/v0.3.3-dev/mdsf.schema.json +++ b/schemas/v0.3.3-dev/mdsf.schema.json @@ -988,6 +988,11 @@ "type": "string", "enum": ["rustywind"] }, + { + "description": "`salt-lint $PATH`", + "type": "string", + "enum": ["salt-lint"] + }, { "description": "`scalafmt --quiet --mode any $PATH`", "type": "string", diff --git a/tools/salt-lint/plugin.json b/tools/salt-lint/plugin.json new file mode 100644 index 00000000..fb4aeffe --- /dev/null +++ b/tools/salt-lint/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "salt-lint", + "categories": ["linter"], + "commands": { + "": ["$PATH"] + }, + "description": "A command-line utility that checks for best practices in SaltStack", + "homepage": "https://github.com/warpnet/salt-lint", + "languages": ["salt"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}