Skip to content

Commit

Permalink
feat: add support for hadolint (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 12, 2025
1 parent 9bb58be commit 1fcfc83
Show file tree
Hide file tree
Showing 6 changed files with 64 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 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)
- feat: add support for statix [`#589`](https://github.com/hougesen/mdsf/pull/589)
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 223 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 224 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -301,6 +301,7 @@ mdsf init
| [golines](https://github.com/segmentio/golines) | A golang formatter that fixes long lines | `formatter` | `go` |
| [google-java-format](https://github.com/google/google-java-format) | Reformats Java source code to comply with Google Java Style | `formatter` | `java` |
| [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` |
| [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` |
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/hadolint.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_hadolint_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("hadolint")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_hadolint_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_hadolint {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub mod goimports_reviser;
pub mod golines;
pub mod google_java_format;
pub mod grain_format;
pub mod hadolint;
pub mod haml_lint;
pub mod hfmt;
pub mod hindent;
Expand Down Expand Up @@ -588,6 +589,10 @@ pub enum Tooling {
/// `grain format $PATH -o $PATH`
GrainFormat,

#[serde(rename = "hadolint")]
/// `hadolint $PATH`
Hadolint,

#[serde(rename = "haml-lint")]
/// `haml-lint --auto-correct $PATH`
HamlLint,
Expand Down Expand Up @@ -1265,6 +1270,7 @@ impl Tooling {
Self::Golines => golines::run(snippet_path),
Self::GoogleJavaFormat => google_java_format::run(snippet_path),
Self::GrainFormat => grain_format::run(snippet_path),
Self::Hadolint => hadolint::run(snippet_path),
Self::HamlLint => haml_lint::run(snippet_path),
Self::Hfmt => hfmt::run(snippet_path),
Self::Hindent => hindent::run(snippet_path),
Expand Down Expand Up @@ -1507,6 +1513,7 @@ impl AsRef<str> for Tooling {
Self::Golines => "golines",
Self::GoogleJavaFormat => "google_java_format",
Self::GrainFormat => "grain_format",
Self::Hadolint => "hadolint",
Self::HamlLint => "haml_lint",
Self::Hfmt => "hfmt",
Self::Hindent => "hindent",
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 @@ -498,6 +498,11 @@
"type": "string",
"enum": ["grain:format"]
},
{
"description": "`hadolint $PATH`",
"type": "string",
"enum": ["hadolint"]
},
{
"description": "`haml-lint --auto-correct $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/hadolint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "hadolint",
"categories": ["linter"],
"commands": {
"": ["$PATH"]
},
"description": "Dockerfile linter, validate inline bash, written in Haskell",
"homepage": "https://github.com/hadolint/hadolint",
"languages": ["dockerfile"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 1fcfc83

Please sign in to comment.