Skip to content

Commit

Permalink
feat: add support for meson fmt (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 12, 2025
1 parent 510041d commit 1785102
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.3.2...HEAD)

- feat: feat: add support for jsonnet-lint [`#586`](https://github.com/hougesen/mdsf/pull/586)
- 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)
- feat: add support for cmake-format [`#584`](https://github.com/hougesen/mdsf/pull/584)
- feat: nushell shell completion [`#583`](https://github.com/hougesen/mdsf/pull/583)
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 218 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 219 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -332,6 +332,7 @@ mdsf init
| [markuplint](https://markuplint.dev/) | An HTML linter for all markup developers | `linter` | `html` |
| [mdformat](https://github.com/executablebooks/mdformat) | CommonMark compliant Markdown formatter | `formatter` | `markdwon` |
| [mdslw](https://github.com/razziel89/mdslw) | Prepare your markdown for easy diff'ing! | `formatter` | `markdown` |
| [meson](https://mesonbuild.com/) | Meson is an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible | `formatter` | `meson` |
| [misspell](https://github.com/client9/misspell/) | Correct commonly misspelled English words in source files | `autocorrection` | |
| [mix](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) | Code formatter for Elixir | `formatter` | `elixir` |
| [mojo](https://docs.modular.com/mojo/cli/format) | Formats Mojo source files | `formatter` | `mojo` |
Expand Down
36 changes: 36 additions & 0 deletions mdsf/src/tools/meson_fmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::process::Command;

use crate::{error::MdsfError, execution::execute_command, runners::CommandType};

#[inline]
fn set_meson_fmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("fmt");
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("meson")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_meson_fmt_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_meson_fmt {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub mod markdownlint_cli_2;
pub mod markuplint;
pub mod mdformat;
pub mod mdslw;
pub mod meson_fmt;
pub mod misspell;
pub mod mix_format;
pub mod mojo_format;
Expand Down Expand Up @@ -710,6 +711,10 @@ pub enum Tooling {
/// `mdslw $PATH`
Mdslw,

#[serde(rename = "meson:fmt")]
/// `meson fmt -i $PATH`
MesonFmt,

#[serde(rename = "misspell")]
/// `misspell -w $PATH`
Misspell,
Expand Down Expand Up @@ -1267,6 +1272,7 @@ impl Tooling {
Self::Markuplint => markuplint::run(snippet_path),
Self::Mdformat => mdformat::run(snippet_path),
Self::Mdslw => mdslw::run(snippet_path),
Self::MesonFmt => meson_fmt::run(snippet_path),
Self::Misspell => misspell::run(snippet_path),
Self::MixFormat => mix_format::run(snippet_path),
Self::MojoFormat => mojo_format::run(snippet_path),
Expand Down Expand Up @@ -1503,6 +1509,7 @@ impl AsRef<str> for Tooling {
Self::Markuplint => "markuplint",
Self::Mdformat => "mdformat",
Self::Mdslw => "mdslw",
Self::MesonFmt => "meson_fmt",
Self::Misspell => "misspell",
Self::MixFormat => "mix_format",
Self::MojoFormat => "mojo_format",
Expand Down
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 @@ -658,6 +658,11 @@
"type": "string",
"enum": ["mdslw"]
},
{
"description": "`meson fmt -i $PATH`",
"type": "string",
"enum": ["meson:fmt"]
},
{
"description": "`misspell -w $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/meson/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "meson",
"categories": ["formatter"],
"commands": {
"fmt": ["fmt", "-i", "$PATH"]
},
"description": "Meson is an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible",
"homepage": "https://mesonbuild.com/",
"languages": ["meson"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 1785102

Please sign in to comment.