diff --git a/CHANGELOG.md b/CHANGELOG.md index a9aba2b..14b0e5a 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.3.2...HEAD) +- feat: add support for hclfmt [`#593`](https://github.com/hougesen/mdsf/pull/593) - feat: add support for hadolint [`#592`](https://github.com/hougesen/mdsf/pull/592) - feat: add support for curlylint [`#591`](https://github.com/hougesen/mdsf/pull/591) - feat: add support for toml-sort [`#590`](https://github.com/hougesen/mdsf/pull/590) diff --git a/README.md b/README.md index 8ab8117..d305e32 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`mdsf` currently supports 224 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 225 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -303,6 +303,7 @@ mdsf init | [grain](https://grain-lang.org/docs/tooling/grain_cli) | Code formatter for the Grain programming language | `formatter` | `grain` | | [hadolint](https://github.com/hadolint/hadolint) | Dockerfile linter, validate inline bash, written in Haskell | `linter` | `dockerfile` | | [haml-lint](https://github.com/sds/haml-lint) | Tool for writing clean and consistent HAML | `linter` | `haml` | +| [hclfmt](https://github.com/hashicorp/hcl) | Formatter for hcl files | `formatter` | `hcl` | | [hfmt](https://github.com/danstiner/hfmt) | Format Haskell programs. Inspired by the gofmt utility | `formatter` | `haskell` | | [hindent](https://github.com/mihaimaruseac/hindent) | Extensible Haskell pretty printer | `formatter` | `haskell` | | [hlint](https://github.com/ndmitchell/hlint) | Haskell source code suggestions | `linter` | `haskell` | diff --git a/mdsf/src/tools/hclfmt.rs b/mdsf/src/tools/hclfmt.rs new file mode 100644 index 0000000..f021953 --- /dev/null +++ b/mdsf/src/tools/hclfmt.rs @@ -0,0 +1,35 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_hclfmt_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), MdsfError> { + let commands = [CommandType::Direct("hclfmt")]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_hclfmt_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_hclfmt {} diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 18ad33b..d03e4c7 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -88,6 +88,7 @@ pub mod google_java_format; pub mod grain_format; pub mod hadolint; pub mod haml_lint; +pub mod hclfmt; pub mod hfmt; pub mod hindent; pub mod hlint; @@ -597,6 +598,10 @@ pub enum Tooling { /// `haml-lint --auto-correct $PATH` HamlLint, + #[serde(rename = "hclfmt")] + /// `hclfmt -w $PATH` + Hclfmt, + #[serde(rename = "hfmt")] /// `hfmt -w $PATH` Hfmt, @@ -1272,6 +1277,7 @@ impl Tooling { Self::GrainFormat => grain_format::run(snippet_path), Self::Hadolint => hadolint::run(snippet_path), Self::HamlLint => haml_lint::run(snippet_path), + Self::Hclfmt => hclfmt::run(snippet_path), Self::Hfmt => hfmt::run(snippet_path), Self::Hindent => hindent::run(snippet_path), Self::Hlint => hlint::run(snippet_path), @@ -1515,6 +1521,7 @@ impl AsRef for Tooling { Self::GrainFormat => "grain_format", Self::Hadolint => "hadolint", Self::HamlLint => "haml_lint", + Self::Hclfmt => "hclfmt", Self::Hfmt => "hfmt", Self::Hindent => "hindent", Self::Hlint => "hlint", diff --git a/schemas/v0.3.3-dev/mdsf.schema.json b/schemas/v0.3.3-dev/mdsf.schema.json index 666070a..d075cd8 100644 --- a/schemas/v0.3.3-dev/mdsf.schema.json +++ b/schemas/v0.3.3-dev/mdsf.schema.json @@ -508,6 +508,11 @@ "type": "string", "enum": ["haml-lint"] }, + { + "description": "`hclfmt -w $PATH`", + "type": "string", + "enum": ["hclfmt"] + }, { "description": "`hfmt -w $PATH`", "type": "string", diff --git a/tools/hclfmt/plugin.json b/tools/hclfmt/plugin.json new file mode 100644 index 0000000..a8e06ae --- /dev/null +++ b/tools/hclfmt/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "hclfmt", + "categories": ["formatter"], + "commands": { + "": ["-w", "$PATH"] + }, + "description": "Formatter for hcl files", + "homepage": "https://github.com/hashicorp/hcl", + "languages": ["hcl"], + "name": null, + "npm": null, + "php": null, + "tests": [] +}