diff --git a/CHANGELOG.md b/CHANGELOG.md index c14e42cb..8e811405 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.2.7...HEAD) +- feat: support dockfmt [`#523`](https://github.com/hougesen/mdsf/pull/523) - feat: support json5format [`#522`](https://github.com/hougesen/mdsf/pull/522) - feat: support kdoc-formatter [`#521`](https://github.com/hougesen/mdsf/pull/521) - feat: support djade [`#520`](https://github.com/hougesen/mdsf/pull/520) diff --git a/README.md b/README.md index 92eb0356..1aed9b62 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`mdsf` currently supports 213 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 +`mdsf` currently supports 214 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 | Name | Command | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -240,6 +240,7 @@ mdsf init | `djade` | `djade PATH` | | `djlint` | `djlint PATH --reformat` | | `docformatter` | `docformatter --in-place PATH` | +| `dockfmt` | `dockfmt fmt -w PATH` | | `docstrfmt` | `docstrfmt PATH` | | `doctoc` | `doctoc PATH` | | `dotenv-linter:fix` | `dotenv-linter fix PATH` | diff --git a/mdsf/src/tools/dockfmt.rs b/mdsf/src/tools/dockfmt.rs new file mode 100644 index 00000000..4b77ad58 --- /dev/null +++ b/mdsf/src/tools/dockfmt.rs @@ -0,0 +1,36 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_dockfmt_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("fmt"); + 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("dockfmt")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_dockfmt_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_dockfmt {} diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 18cb287b..604fd6bf 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -50,6 +50,7 @@ pub mod dhall; pub mod djade; pub mod djlint; pub mod docformatter; +pub mod dockfmt; pub mod docstrfmt; pub mod doctoc; pub mod dotenv_linter_fix; @@ -424,6 +425,10 @@ pub enum Tooling { /// `docformatter --in-place $PATH` Docformatter, + #[serde(rename = "dockfmt")] + /// `dockfmt fmt -w $PATH` + Dockfmt, + #[serde(rename = "docstrfmt")] /// `docstrfmt $PATH` Docstrfmt, @@ -1129,6 +1134,7 @@ impl Tooling { Self::Djade => djade::run(snippet_path), Self::Djlint => djlint::run(snippet_path), Self::Docformatter => docformatter::run(snippet_path), + Self::Dockfmt => dockfmt::run(snippet_path), Self::Docstrfmt => docstrfmt::run(snippet_path), Self::Doctoc => doctoc::run(snippet_path), Self::DotenvLinterFix => dotenv_linter_fix::run(snippet_path), @@ -1351,6 +1357,7 @@ impl AsRef for Tooling { Self::Djade => "djade", Self::Djlint => "djlint", Self::Docformatter => "docformatter", + Self::Dockfmt => "dockfmt", Self::Docstrfmt => "docstrfmt", Self::Doctoc => "doctoc", Self::DotenvLinterFix => "dotenv_linter_fix", diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index 5dba378e..806c4b0e 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -318,6 +318,11 @@ "type": "string", "enum": ["docformatter"] }, + { + "description": "`dockfmt fmt -w $PATH`", + "type": "string", + "enum": ["dockfmt"] + }, { "description": "`docstrfmt $PATH`", "type": "string", diff --git a/tools/dockfmt/plugin.json b/tools/dockfmt/plugin.json new file mode 100644 index 00000000..dd227e29 --- /dev/null +++ b/tools/dockfmt/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "dockfmt", + "categories": ["formatter"], + "commands": { + "": ["fmt", "-w", "$PATH"] + }, + "description": "Dockerfile format and parser. Like `gofmt` but for Dockerfiles", + "homepage": "https://github.com/jessfraz/dockfmt", + "languages": ["docker"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}