Skip to content

Commit

Permalink
feat: support nufmt (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Dec 27, 2024
1 parent 79a6a15 commit 189e1aa
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 8 deletions.
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: support nufmt [`#559`](https://github.com/hougesen/mdsf/pull/559)
- build: update cargo-dist to v0.27.0 [`#558`](https://github.com/hougesen/mdsf/pull/558)
- build: update cargo-dist to v0.26.1 [`#557`](https://github.com/hougesen/mdsf/pull/557)
- chore: update dev version to v0.3.3-dev [`#556`](https://github.com/hougesen/mdsf/pull/556)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 210 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 211 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -337,6 +337,7 @@ mdsf init
| [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) | Nix code formatter for nixpkgs | `formatter` | `nix` |
| [nph](https://github.com/arnetheduck/nph) | An opinionated code formatter for Nim | `formatter` | `nim` |
| [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files | `formatter`, `linter` | `groovy` |
| [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` |
| [opa](https://www.openpolicyagent.org/docs/latest/cli/) | Format Rego source files | `formatter` | `rego` |
Expand Down
6 changes: 1 addition & 5 deletions codegen/src/readme/command_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ pub fn generate(mut readme: String) -> anyhow::Result<String> {

let help = String::from_utf8(execute_command(command)?.stdout)?;

readme = update_readme(
&readme,
&section_name,
&format!("```\n{}\n```", help.trim()),
)?;
readme = update_readme(&readme, section_name, &format!("```\n{}\n```", help.trim()))?;
}

anyhow::Ok(readme)
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/readme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn update_readme(readme: &str, key: &str, value: &str) -> Result<String, reg

let first_value = format!("{start}{end}");

let updated = re.replace(&readme, &first_value);
let updated = re.replace(readme, &first_value);

let update = format!("{start}\n\n{value}\n\n{end}");

Expand Down
2 changes: 1 addition & 1 deletion codegen/src/readme/tool_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn generate(plugins: &[Tool]) -> String {
let name = plugin
.name
.as_ref()
.unwrap_or_else(|| &plugin.binary)
.unwrap_or(&plugin.binary)
.trim()
.to_owned();
let name = if plugin.homepage.is_empty() {
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 @@ -124,6 +124,7 @@ pub mod nixfmt;
pub mod nixpkgs_fmt;
pub mod nph;
pub mod npm_groovy_lint;
pub mod nufmt;
pub mod ocamlformat;
pub mod ocp_indent;
pub mod opa_fmt;
Expand Down Expand Up @@ -725,6 +726,10 @@ pub enum Tooling {
/// `npm-groovy-lint --format $PATH`
NpmGroovyLint,

#[serde(rename = "nufmt")]
/// `nufmt $PATH`
Nufmt,

#[serde(rename = "ocamlformat")]
/// `ocamlformat --ignore-invalid-option --inplace --enable-outside-detected-project $PATH`
Ocamlformat,
Expand Down Expand Up @@ -1228,6 +1233,7 @@ impl Tooling {
Self::NixpkgsFmt => nixpkgs_fmt::run(snippet_path),
Self::Nph => nph::run(snippet_path),
Self::NpmGroovyLint => npm_groovy_lint::run(snippet_path),
Self::Nufmt => nufmt::run(snippet_path),
Self::Ocamlformat => ocamlformat::run(snippet_path),
Self::OcpIndent => ocp_indent::run(snippet_path),
Self::OpaFmt => opa_fmt::run(snippet_path),
Expand Down Expand Up @@ -1455,6 +1461,7 @@ impl AsRef<str> for Tooling {
Self::NixpkgsFmt => "nixpkgs_fmt",
Self::Nph => "nph",
Self::NpmGroovyLint => "npm_groovy_lint",
Self::Nufmt => "nufmt",
Self::Ocamlformat => "ocamlformat",
Self::OcpIndent => "ocp_indent",
Self::OpaFmt => "opa_fmt",
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/nufmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::process::Command;

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

#[inline]
fn set_nufmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg(file_path);
cmd
}

#[inline]
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let commands = [CommandType::Direct("nufmt")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_nufmt_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_nufmt {}
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 @@ -688,6 +688,11 @@
"type": "string",
"enum": ["npm-groovy-lint"]
},
{
"description": "`nufmt $PATH`",
"type": "string",
"enum": ["nufmt"]
},
{
"description": "`ocamlformat --ignore-invalid-option --inplace --enable-outside-detected-project $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/nufmt/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "nufmt",
"categories": ["formatter"],
"commands": {
"": ["$PATH"]
},
"description": "the nushell formatter",
"homepage": "https://github.com/nushell/nufmt",
"languages": ["nushell"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 189e1aa

Please sign in to comment.