Skip to content

Commit

Permalink
feat: add support for toml-sort (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 12, 2025
1 parent d9e3cd9 commit 54975e9
Show file tree
Hide file tree
Showing 6 changed files with 65 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 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)
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 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 |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -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` |
Expand Down
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1613,6 +1619,7 @@ impl AsRef<str> 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",
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/toml_sort.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_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<String>), 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 {}
5 changes: 5 additions & 0 deletions schemas/v0.3.3-dev/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions tools/toml-sort/plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 54975e9

Please sign in to comment.