Skip to content

Commit

Permalink
feat: support hlint (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Oct 26, 2024
1 parent 6ac1a15 commit a04ac16
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

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

- feat: support hlint [`#507`](https://github.com/hougesen/mdsf/pull/507)
- feat: support bslint [`#506`](https://github.com/hougesen/mdsf/pull/506)
- feat: support terragrunt hclfmt [`#505`](https://github.com/hougesen/mdsf/pull/505)
- feat: support shellharden [`#504`](https://github.com/hougesen/mdsf/pull/504)
- feat: support reorder-python-imports [`#503`](https://github.com/hougesen/mdsf/pull/503)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 197 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 198 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -268,6 +268,7 @@ mdsf init
| `haml-lint` | `haml-lint --auto-correct PATH` |
| `hfmt` | `hfmt -w PATH` |
| `hindent` | `hindent PATH` |
| `hlint` | `hlint --refactor -i PATH` |
| `html-beautify` | `html-beautify -r --type html -f PATH` |
| `htmlbeautifier` | `htmlbeautifier PATH` |
| `imba:fmt` | `imba fmt -f PATH` |
Expand Down
36 changes: 36 additions & 0 deletions mdsf/src/tools/hlint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::process::Command;

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

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

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

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_hlint_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_hlint {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub mod grain_format;
pub mod haml_lint;
pub mod hfmt;
pub mod hindent;
pub mod hlint;
pub mod html_beautify;
pub mod htmlbeautifier;
pub mod imba_fmt;
Expand Down Expand Up @@ -520,6 +521,10 @@ pub enum Tooling {
/// `hindent $PATH`
Hindent,

#[serde(rename = "hlint")]
/// `hlint --refactor -i $PATH`
Hlint,

#[serde(rename = "html-beautify")]
/// `html-beautify -r --type html -f $PATH`
HtmlBeautify,
Expand Down Expand Up @@ -1077,6 +1082,7 @@ impl Tooling {
Self::HamlLint => haml_lint::run(snippet_path),
Self::Hfmt => hfmt::run(snippet_path),
Self::Hindent => hindent::run(snippet_path),
Self::Hlint => hlint::run(snippet_path),
Self::HtmlBeautify => html_beautify::run(snippet_path),
Self::Htmlbeautifier => htmlbeautifier::run(snippet_path),
Self::ImbaFmt => imba_fmt::run(snippet_path),
Expand Down Expand Up @@ -1283,6 +1289,7 @@ impl AsRef<str> for Tooling {
Self::HamlLint => "haml_lint",
Self::Hfmt => "hfmt",
Self::Hindent => "hindent",
Self::Hlint => "hlint",
Self::HtmlBeautify => "html_beautify",
Self::Htmlbeautifier => "htmlbeautifier",
Self::ImbaFmt => "imba_fmt",
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.2.7/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@
"type": "string",
"enum": ["hindent"]
},
{
"description": "`hlint --refactor -i $PATH`",
"type": "string",
"enum": ["hlint"]
},
{
"description": "`html-beautify -r --type html -f $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/hlint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "hlint",
"categories": ["linter"],
"commands": {
"": ["--refactor", "-i", "$PATH"]
},
"description": "Haskell source code suggestions",
"homepage": "https://github.com/ndmitchell/hlint",
"languages": ["haskell"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit a04ac16

Please sign in to comment.