Skip to content

Commit

Permalink
feat: add support for odinfmt (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 12, 2025
1 parent 1785102 commit 182cf18
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 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)
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 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 |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -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` |
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 @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1525,6 +1531,7 @@ impl AsRef<str> 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",
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/odinfmt.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_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<String>), 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 {}
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 @@ -738,6 +738,11 @@
"type": "string",
"enum": ["ocp-indent"]
},
{
"description": "`odinfmt -w $PATH`",
"type": "string",
"enum": ["odinfmt"]
},
{
"description": "`opa fmt $PATH -w`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/odinfmt/plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 182cf18

Please sign in to comment.