Skip to content

Commit

Permalink
feat: add support for hclfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jan 12, 2025
1 parent 1fcfc83 commit 9a1d149
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
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: 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)
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 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 |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -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` |
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/hclfmt.rs
Original file line number Diff line number Diff line change
@@ -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<String>), 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 {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1515,6 +1521,7 @@ impl AsRef<str> 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",
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 @@ -508,6 +508,11 @@
"type": "string",
"enum": ["haml-lint"]
},
{
"description": "`hclfmt -w $PATH`",
"type": "string",
"enum": ["hclfmt"]
},
{
"description": "`hfmt -w $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/hclfmt/plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 9a1d149

Please sign in to comment.