Skip to content

Commit

Permalink
feat: add support for statix
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jan 12, 2025
1 parent 182cf18 commit 3f43da0
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`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 |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -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` |
Expand Down
14 changes: 14 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1585,6 +1597,8 @@ impl AsRef<str> 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",
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/statix_check.rs
Original file line number Diff line number Diff line change
@@ -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<String>), 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 {}
35 changes: 35 additions & 0 deletions mdsf/src/tools/statix_fix.rs
Original file line number Diff line number Diff line change
@@ -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<String>), 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 {}
10 changes: 10 additions & 0 deletions schemas/v0.3.3-dev/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions tools/statix/plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 3f43da0

Please sign in to comment.