Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for shellcheck #603

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 shellcheck [`#603`](https://github.com/hougesen/mdsf/pull/603)
- feat: add support for solhint [`#602`](https://github.com/hougesen/mdsf/pull/602)
- feat: add support for salt-lint [`#601`](https://github.com/hougesen/mdsf/pull/601)
- feat: add support for regal [`#600`](https://github.com/hougesen/mdsf/pull/600)
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 234 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 235 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -398,6 +398,7 @@ mdsf init
| [salt-lint](https://github.com/warpnet/salt-lint) | A command-line utility that checks for best practices in SaltStack | `linter` | `salt` |
| [scalafmt](https://github.com/scalameta/scalafmt) | Code formatter for Scala | `formatter` | `scala` |
| [scalariform](https://github.com/scala-ide/scalariform) | Scala source code formatter | `formatter` | `scala` |
| [shellcheck](https://github.com/koalaman/shellcheck) | ShellCheck, a static analysis tool for shell scripts | `linter` | `bash`, `shell` |
| [shellharden](https://github.com/anordal/shellharden) | The corrective bash syntax highlighter | `linter` | `bash`, `shell` |
| [shfmt](https://github.com/mvdan/sh) | Shell script formatter | `formatter` | `shell` |
| [sleek](https://github.com/nrempel/sleek) | Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity | `formatter` | `sql` |
Expand Down
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub mod rustywind;
pub mod salt_lint;
pub mod scalafmt;
pub mod scalariform;
pub mod shellcheck;
pub mod shellharden;
pub mod shfmt;
pub mod sleek;
Expand Down Expand Up @@ -1004,6 +1005,10 @@ pub enum Tooling {
/// `scalariform $PATH`
Scalariform,

#[serde(rename = "shellcheck")]
/// `shellcheck $PATH`
Shellcheck,

#[serde(rename = "shellharden")]
/// `shellharden --transform --replace $PATH`
Shellharden,
Expand Down Expand Up @@ -1426,6 +1431,7 @@ impl Tooling {
Self::SaltLint => salt_lint::run(snippet_path),
Self::Scalafmt => scalafmt::run(snippet_path),
Self::Scalariform => scalariform::run(snippet_path),
Self::Shellcheck => shellcheck::run(snippet_path),
Self::Shellharden => shellharden::run(snippet_path),
Self::Shfmt => shfmt::run(snippet_path),
Self::Sleek => sleek::run(snippet_path),
Expand Down Expand Up @@ -1680,6 +1686,7 @@ impl AsRef<str> for Tooling {
Self::SaltLint => "salt_lint",
Self::Scalafmt => "scalafmt",
Self::Scalariform => "scalariform",
Self::Shellcheck => "shellcheck",
Self::Shellharden => "shellharden",
Self::Shfmt => "shfmt",
Self::Sleek => "sleek",
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/shellcheck.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_shellcheck_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("shellcheck")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_shellcheck_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_shellcheck {}
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 @@ -1003,6 +1003,11 @@
"type": "string",
"enum": ["scalariform"]
},
{
"description": "`shellcheck $PATH`",
"type": "string",
"enum": ["shellcheck"]
},
{
"description": "`shellharden --transform --replace $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/shellcheck/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "shellcheck",
"categories": ["linter"],
"commands": {
"": ["$PATH"]
},
"description": "ShellCheck, a static analysis tool for shell scripts",
"homepage": "https://github.com/koalaman/shellcheck",
"languages": ["shell", "bash"],
"name": null,
"npm": null,
"php": null,
"tests": []
}
Loading