diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c7d2eba..9bc749a6 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 toml-sort [`#590`](https://github.com/hougesen/mdsf/pull/590) - 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) diff --git a/README.md b/README.md index a7401ad3..f750150c 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`mdsf` currently supports 221 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 222 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -414,6 +414,7 @@ mdsf init | [tex-fmt](https://github.com/WGUNDERWOOD/tex-fmt) | An extremely fast LaTeX formatter written in Rust | `formatter` | `latex` | | [tlint](https://github.com/tighten/tlint) | Tighten linter for Laravel conventions | `linter` | `php` | | [tofu](https://opentofu.org/docs/cli/commands/fmt/) | The tofu fmt command is used to rewrite OpenTofu configuration files to a canonical format and style | `formatter` | `terraform`, `tofu` | +| [toml-sort](https://github.com/pappasam/toml-sort) | A command line utility to sort and format toml files | `formatter` | `toml` | | [topiary](https://github.com/tweag/topiary) | Topiary aims to be a uniform formatter for simple languages, as part of the Tree-sitter ecosystem | `formatter` | | | [ts-standard](https://github.com/standard/ts-standard) | Typescript style guide, linter, and formatter using StandardJS | `formatter`, `linter` | `typescript` | | [tsqllint](https://github.com/tsqllint/tsqllint) | Configurable linting for TSQL | `linter` | `sql` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 2805b760..a533dcfc 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -204,6 +204,7 @@ pub mod terragrunt_hclfmt; pub mod tex_fmt; pub mod tlint_format; pub mod tofu_fmt; +pub mod toml_sort; pub mod topiary; pub mod ts_standard; pub mod tsqllint; @@ -1058,6 +1059,10 @@ pub enum Tooling { /// `tofu fmt -write=true $PATH` TofuFmt, + #[serde(rename = "toml-sort")] + /// `toml-sort -i $PATH` + TomlSort, + #[serde(rename = "topiary")] /// `topiary format $PATH` Topiary, @@ -1373,6 +1378,7 @@ impl Tooling { Self::TexFmt => tex_fmt::run(snippet_path), Self::TlintFormat => tlint_format::run(snippet_path), Self::TofuFmt => tofu_fmt::run(snippet_path), + Self::TomlSort => toml_sort::run(snippet_path), Self::Topiary => topiary::run(snippet_path), Self::TsStandard => ts_standard::run(snippet_path), Self::Tsqllint => tsqllint::run(snippet_path), @@ -1613,6 +1619,7 @@ impl AsRef for Tooling { Self::TexFmt => "tex_fmt", Self::TlintFormat => "tlint_format", Self::TofuFmt => "tofu_fmt", + Self::TomlSort => "toml_sort", Self::Topiary => "topiary", Self::TsStandard => "ts_standard", Self::Tsqllint => "tsqllint", diff --git a/mdsf/src/tools/toml_sort.rs b/mdsf/src/tools/toml_sort.rs new file mode 100644 index 00000000..1aaf6058 --- /dev/null +++ b/mdsf/src/tools/toml_sort.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_toml_sort_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + 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("toml-sort")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_toml_sort_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_toml_sort {} diff --git a/schemas/v0.3.3-dev/mdsf.schema.json b/schemas/v0.3.3-dev/mdsf.schema.json index c8a9879d..0bf658aa 100644 --- a/schemas/v0.3.3-dev/mdsf.schema.json +++ b/schemas/v0.3.3-dev/mdsf.schema.json @@ -1088,6 +1088,11 @@ "type": "string", "enum": ["tofu:fmt"] }, + { + "description": "`toml-sort -i $PATH`", + "type": "string", + "enum": ["toml-sort"] + }, { "description": "`topiary format $PATH`", "type": "string", diff --git a/tools/toml-sort/plugin.json b/tools/toml-sort/plugin.json new file mode 100644 index 00000000..1a4b7d50 --- /dev/null +++ b/tools/toml-sort/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "toml-sort", + "categories": ["formatter"], + "commands": { + "": ["-i", "$PATH"] + }, + "description": "A command line utility to sort and format toml files", + "homepage": "https://github.com/pappasam/toml-sort", + "languages": ["toml"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}