diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bd2433..58ff78d 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 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) - feat: add support for deadnix [`#585`](https://github.com/hougesen/mdsf/pull/585) diff --git a/README.md b/README.md index 6cd7b99..d707916 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`mdsf` currently supports 219 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 220 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -348,6 +348,7 @@ mdsf init | [nufmt](https://github.com/nushell/nufmt) | the nushell formatter | `formatter` | `nushell` | | [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) | Auto-formatter for OCaml code | `formatter` | `ocaml` | | [ocp-indent](https://github.com/OCamlPro/ocp-indent) | Indentation tool for OCaml | `formatter` | `ocaml` | +| [odinfmt](https://github.com/DanielGavin/ols) | Formatter for the Odin programming language | `formatter` | `odin` | | [opa](https://www.openpolicyagent.org/docs/latest/cli/) | Format Rego source files | `formatter` | `rego` | | [ormolu](https://github.com/tweag/ormolu) | A formatter for Haskell source code | `formatter` | `haskell` | | [oxlint](https://oxc.rs/docs/guide/usage/linter.html) | Oxlint is designed to catch erroneous or useless code without requiring any configurations by default | `linter` | `javascript`, `typescript` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 91d0e74..3e7dd0c 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -134,6 +134,7 @@ pub mod npm_groovy_lint; pub mod nufmt; pub mod ocamlformat; pub mod ocp_indent; +pub mod odinfmt; pub mod opa_fmt; pub mod ormolu; pub mod oxlint; @@ -775,6 +776,10 @@ pub enum Tooling { /// `ocp-indent --inplace $PATH` OcpIndent, + #[serde(rename = "odinfmt")] + /// `odinfmt -w $PATH` + Odinfmt, + #[serde(rename = "opa:fmt")] /// `opa fmt $PATH -w` OpaFmt, @@ -1288,6 +1293,7 @@ impl Tooling { Self::Nufmt => nufmt::run(snippet_path), Self::Ocamlformat => ocamlformat::run(snippet_path), Self::OcpIndent => ocp_indent::run(snippet_path), + Self::Odinfmt => odinfmt::run(snippet_path), Self::OpaFmt => opa_fmt::run(snippet_path), Self::Ormolu => ormolu::run(snippet_path), Self::Oxlint => oxlint::run(snippet_path), @@ -1525,6 +1531,7 @@ impl AsRef for Tooling { Self::Nufmt => "nufmt", Self::Ocamlformat => "ocamlformat", Self::OcpIndent => "ocp_indent", + Self::Odinfmt => "odinfmt", Self::OpaFmt => "opa_fmt", Self::Ormolu => "ormolu", Self::Oxlint => "oxlint", diff --git a/mdsf/src/tools/odinfmt.rs b/mdsf/src/tools/odinfmt.rs new file mode 100644 index 0000000..47a4df5 --- /dev/null +++ b/mdsf/src/tools/odinfmt.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_odinfmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("-w"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [CommandType::Direct("odinfmt")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_odinfmt_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_odinfmt {} diff --git a/schemas/v0.3.3-dev/mdsf.schema.json b/schemas/v0.3.3-dev/mdsf.schema.json index 5ccb11d..f443600 100644 --- a/schemas/v0.3.3-dev/mdsf.schema.json +++ b/schemas/v0.3.3-dev/mdsf.schema.json @@ -738,6 +738,11 @@ "type": "string", "enum": ["ocp-indent"] }, + { + "description": "`odinfmt -w $PATH`", + "type": "string", + "enum": ["odinfmt"] + }, { "description": "`opa fmt $PATH -w`", "type": "string", diff --git a/tools/odinfmt/plugin.json b/tools/odinfmt/plugin.json new file mode 100644 index 0000000..5cb0ee7 --- /dev/null +++ b/tools/odinfmt/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "odinfmt", + "categories": ["formatter"], + "commands": { + "": ["-w", "$PATH"] + }, + "description": "Formatter for the Odin programming language", + "homepage": "https://github.com/DanielGavin/ols", + "languages": ["odin"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}