From 3f43da022ac814fb92b533ea49d52c97e791cd6d Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 12 Jan 2025 17:51:21 +0100 Subject: [PATCH] feat: add support for statix --- CHANGELOG.md | 1 + README.md | 3 ++- mdsf/src/tools/mod.rs | 14 ++++++++++++ mdsf/src/tools/statix_check.rs | 35 +++++++++++++++++++++++++++++ mdsf/src/tools/statix_fix.rs | 35 +++++++++++++++++++++++++++++ schemas/v0.3.3-dev/mdsf.schema.json | 10 +++++++++ tools/statix/plugin.json | 16 +++++++++++++ 7 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 mdsf/src/tools/statix_check.rs create mode 100644 mdsf/src/tools/statix_fix.rs create mode 100644 tools/statix/plugin.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 58ff78d..1c7d2eb 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 statix [`#589`](https://github.com/hougesen/mdsf/pull/589) - feat: add support for odinfmt [`#588`](https://github.com/hougesen/mdsf/pull/588) - feat: add support for meson fmt [`#587`](https://github.com/hougesen/mdsf/pull/587) - feat: add support for jsonnet-lint [`#586`](https://github.com/hougesen/mdsf/pull/586) diff --git a/README.md b/README.md index d707916..a7401ad 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`mdsf` currently supports 220 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 221 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -399,6 +399,7 @@ mdsf init | [sqruff](https://github.com/quarylabs/sqruff) | Fast SQL formatter/linter | `formatter`, `linter` | `sql` | | [standardjs](https://github.com/standard/standard) | JavaScript style guide, linter, and formatter | `formatter`, `linter` | `javascript` | | [standardrb](https://github.com/standardrb/standard) | Ruby's bikeshed-proof linter and formatter | `formatter`, `linter` | `ruby` | +| [statix](https://github.com/oppiliappan/statix) | lints and suggestions for the nix programming language | `linter` | `nix` | | [stylefmt](https://github.com/matype/stylefmt) | stylefmt is a tool that automatically formats stylesheets | `formatter` | `css`, `scss` | | [stylelint](https://github.com/stylelint/stylelint) | A mighty CSS linter that helps you avoid errors and enforce conventions | `linter` | `css`, `scss` | | [stylish-haskell](https://github.com/haskell/stylish-haskell) | Haskell code prettifier | `formatter` | `haskell` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 3e7dd0c..2805b76 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -188,6 +188,8 @@ pub mod sqlfmt; pub mod sqruff; pub mod standardjs; pub mod standardrb; +pub mod statix_check; +pub mod statix_fix; pub mod stylefmt; pub mod stylelint; pub mod stylish_haskell; @@ -992,6 +994,14 @@ pub enum Tooling { /// `standardrb --fix $PATH` Standardrb, + #[serde(rename = "statix:check")] + /// `statix check $PATH` + StatixCheck, + + #[serde(rename = "statix:fix")] + /// `statix fix $PATH` + StatixFix, + #[serde(rename = "stylefmt")] /// `stylefmt $PATH` Stylefmt, @@ -1347,6 +1357,8 @@ impl Tooling { Self::Sqruff => sqruff::run(snippet_path), Self::Standardjs => standardjs::run(snippet_path), Self::Standardrb => standardrb::run(snippet_path), + Self::StatixCheck => statix_check::run(snippet_path), + Self::StatixFix => statix_fix::run(snippet_path), Self::Stylefmt => stylefmt::run(snippet_path), Self::Stylelint => stylelint::run(snippet_path), Self::StylishHaskell => stylish_haskell::run(snippet_path), @@ -1585,6 +1597,8 @@ impl AsRef for Tooling { Self::Sqruff => "sqruff", Self::Standardjs => "standardjs", Self::Standardrb => "standardrb", + Self::StatixCheck => "statix_check", + Self::StatixFix => "statix_fix", Self::Stylefmt => "stylefmt", Self::Stylelint => "stylelint", Self::StylishHaskell => "stylish_haskell", diff --git a/mdsf/src/tools/statix_check.rs b/mdsf/src/tools/statix_check.rs new file mode 100644 index 0000000..46e6fc6 --- /dev/null +++ b/mdsf/src/tools/statix_check.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_statix_check_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("check"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("statix")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_statix_check_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_statix_check {} diff --git a/mdsf/src/tools/statix_fix.rs b/mdsf/src/tools/statix_fix.rs new file mode 100644 index 0000000..374fe66 --- /dev/null +++ b/mdsf/src/tools/statix_fix.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_statix_fix_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("fix"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("statix")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_statix_fix_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_statix_fix {} diff --git a/schemas/v0.3.3-dev/mdsf.schema.json b/schemas/v0.3.3-dev/mdsf.schema.json index f443600..c8a9879 100644 --- a/schemas/v0.3.3-dev/mdsf.schema.json +++ b/schemas/v0.3.3-dev/mdsf.schema.json @@ -1008,6 +1008,16 @@ "type": "string", "enum": ["standardrb"] }, + { + "description": "`statix check $PATH`", + "type": "string", + "enum": ["statix:check"] + }, + { + "description": "`statix fix $PATH`", + "type": "string", + "enum": ["statix:fix"] + }, { "description": "`stylefmt $PATH`", "type": "string", diff --git a/tools/statix/plugin.json b/tools/statix/plugin.json new file mode 100644 index 0000000..fb39902 --- /dev/null +++ b/tools/statix/plugin.json @@ -0,0 +1,16 @@ +{ + "$schema": "../tool.schema.json", + "binary": "statix", + "categories": ["linter"], + "commands": { + "check": ["check", "$PATH"], + "fix": ["fix", "$PATH"] + }, + "description": "lints and suggestions for the nix programming language", + "homepage": "https://github.com/oppiliappan/statix", + "languages": ["nix"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}