Skip to content

Commit 1785102

Browse files
authored
feat: add support for meson fmt (#587)
1 parent 510041d commit 1785102

File tree

6 files changed

+67
-2
lines changed

6 files changed

+67
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

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

9-
- feat: feat: add support for jsonnet-lint [`#586`](https://github.com/hougesen/mdsf/pull/586)
9+
- feat: add support for meson fmt [`#587`](https://github.com/hougesen/mdsf/pull/587)
10+
- feat: add support for jsonnet-lint [`#586`](https://github.com/hougesen/mdsf/pull/586)
1011
- feat: add support for deadnix [`#585`](https://github.com/hougesen/mdsf/pull/585)
1112
- feat: add support for cmake-format [`#584`](https://github.com/hougesen/mdsf/pull/584)
1213
- feat: nushell shell completion [`#583`](https://github.com/hougesen/mdsf/pull/583)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ mdsf init
214214
215215
<!-- START_SECTION:supported-tools -->
216216

217-
`mdsf` currently supports 218 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
217+
`mdsf` currently supports 219 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
218218

219219
| Name | Description | Categories | Languages |
220220
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
@@ -332,6 +332,7 @@ mdsf init
332332
| [markuplint](https://markuplint.dev/) | An HTML linter for all markup developers | `linter` | `html` |
333333
| [mdformat](https://github.com/executablebooks/mdformat) | CommonMark compliant Markdown formatter | `formatter` | `markdwon` |
334334
| [mdslw](https://github.com/razziel89/mdslw) | Prepare your markdown for easy diff'ing! | `formatter` | `markdown` |
335+
| [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` |
335336
| [misspell](https://github.com/client9/misspell/) | Correct commonly misspelled English words in source files | `autocorrection` | |
336337
| [mix](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html) | Code formatter for Elixir | `formatter` | `elixir` |
337338
| [mojo](https://docs.modular.com/mojo/cli/format) | Formats Mojo source files | `formatter` | `mojo` |

mdsf/src/tools/meson_fmt.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::process::Command;
2+
3+
use crate::{error::MdsfError, execution::execute_command, runners::CommandType};
4+
5+
#[inline]
6+
fn set_meson_fmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
7+
cmd.arg("fmt");
8+
cmd.arg("-i");
9+
cmd.arg(file_path);
10+
cmd
11+
}
12+
13+
#[inline]
14+
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
15+
let commands = [CommandType::Direct("meson")];
16+
17+
for (index, cmd) in commands.iter().enumerate() {
18+
let cmd = set_meson_fmt_args(cmd.build(), file_path);
19+
let execution_result = execute_command(cmd, file_path);
20+
21+
if index == commands.len() - 1 {
22+
return execution_result;
23+
}
24+
25+
if let Ok(r) = execution_result {
26+
if !r.0 {
27+
return Ok(r);
28+
}
29+
}
30+
}
31+
32+
Ok((true, None))
33+
}
34+
35+
#[cfg(test)]
36+
mod test_meson_fmt {}

mdsf/src/tools/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub mod markdownlint_cli_2;
118118
pub mod markuplint;
119119
pub mod mdformat;
120120
pub mod mdslw;
121+
pub mod meson_fmt;
121122
pub mod misspell;
122123
pub mod mix_format;
123124
pub mod mojo_format;
@@ -710,6 +711,10 @@ pub enum Tooling {
710711
/// `mdslw $PATH`
711712
Mdslw,
712713

714+
#[serde(rename = "meson:fmt")]
715+
/// `meson fmt -i $PATH`
716+
MesonFmt,
717+
713718
#[serde(rename = "misspell")]
714719
/// `misspell -w $PATH`
715720
Misspell,
@@ -1267,6 +1272,7 @@ impl Tooling {
12671272
Self::Markuplint => markuplint::run(snippet_path),
12681273
Self::Mdformat => mdformat::run(snippet_path),
12691274
Self::Mdslw => mdslw::run(snippet_path),
1275+
Self::MesonFmt => meson_fmt::run(snippet_path),
12701276
Self::Misspell => misspell::run(snippet_path),
12711277
Self::MixFormat => mix_format::run(snippet_path),
12721278
Self::MojoFormat => mojo_format::run(snippet_path),
@@ -1503,6 +1509,7 @@ impl AsRef<str> for Tooling {
15031509
Self::Markuplint => "markuplint",
15041510
Self::Mdformat => "mdformat",
15051511
Self::Mdslw => "mdslw",
1512+
Self::MesonFmt => "meson_fmt",
15061513
Self::Misspell => "misspell",
15071514
Self::MixFormat => "mix_format",
15081515
Self::MojoFormat => "mojo_format",

schemas/v0.3.3-dev/mdsf.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@
658658
"type": "string",
659659
"enum": ["mdslw"]
660660
},
661+
{
662+
"description": "`meson fmt -i $PATH`",
663+
"type": "string",
664+
"enum": ["meson:fmt"]
665+
},
661666
{
662667
"description": "`misspell -w $PATH`",
663668
"type": "string",

tools/meson/plugin.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "../tool.schema.json",
3+
"binary": "meson",
4+
"categories": ["formatter"],
5+
"commands": {
6+
"fmt": ["fmt", "-i", "$PATH"]
7+
},
8+
"description": "Meson is an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible",
9+
"homepage": "https://mesonbuild.com/",
10+
"languages": ["meson"],
11+
"name": null,
12+
"npm": null,
13+
"php": null,
14+
"tests": []
15+
}

0 commit comments

Comments
 (0)