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: support shellharden #504

Merged
merged 1 commit into from
Oct 26, 2024
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.2.7...HEAD)

- feat: support shellharden [`#504`](https://github.com/hougesen/mdsf/pull/504)
- feat: support reorder-python-imports [`#503`](https://github.com/hougesen/mdsf/pull/503)
- feat: support reformat-gherkin [`#502`](https://github.com/hougesen/mdsf/pull/502)
- deps(clap): upgrade to 4.5.20 [`#501`](https://github.com/hougesen/mdsf/pull/501)
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 194 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 195 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -337,6 +337,7 @@ mdsf init
| `rustywind` | `rustywind --write PATH` |
| `scalafmt` | `scalafmt --quiet --mode any PATH` |
| `scalariform` | `scalariform PATH` |
| `shellharden` | `shellharden --transform --replace PATH` |
| `shfmt` | `shfmt --write PATH` |
| `sleek` | `sleek PATH` |
| `smlfmt` | `smlfmt --force PATH` |
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 @@ -147,6 +147,7 @@ pub mod rustfmt;
pub mod rustywind;
pub mod scalafmt;
pub mod scalariform;
pub mod shellharden;
pub mod shfmt;
pub mod sleek;
pub mod smlfmt;
Expand Down Expand Up @@ -793,6 +794,10 @@ pub enum Tooling {
/// `scalariform $PATH`
Scalariform,

#[serde(rename = "shellharden")]
/// `shellharden --transform --replace $PATH`
Shellharden,

#[serde(rename = "shfmt")]
/// `shfmt --write $PATH`
Shfmt,
Expand Down Expand Up @@ -1131,6 +1136,7 @@ impl Tooling {
Self::Rustywind => rustywind::run(snippet_path),
Self::Scalafmt => scalafmt::run(snippet_path),
Self::Scalariform => scalariform::run(snippet_path),
Self::Shellharden => shellharden::run(snippet_path),
Self::Shfmt => shfmt::run(snippet_path),
Self::Sleek => sleek::run(snippet_path),
Self::Smlfmt => smlfmt::run(snippet_path),
Expand Down Expand Up @@ -1334,6 +1340,7 @@ impl AsRef<str> for Tooling {
Self::Rustywind => "rustywind",
Self::Scalafmt => "scalafmt",
Self::Scalariform => "scalariform",
Self::Shellharden => "shellharden",
Self::Shfmt => "shfmt",
Self::Sleek => "sleek",
Self::Smlfmt => "smlfmt",
Expand Down
36 changes: 36 additions & 0 deletions mdsf/src/tools/shellharden.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_shellharden_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("--transform");
cmd.arg("--replace");
cmd.arg(file_path);
cmd
}

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

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_shellharden_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_shellharden {}
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 @@ -803,6 +803,11 @@
"type": "string",
"enum": ["scalariform"]
},
{
"description": "`shellharden --transform --replace $PATH`",
"type": "string",
"enum": ["shellharden"]
},
{
"description": "`shfmt --write $PATH`",
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion tools/djlint/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../tool.schema.json",
"binary": "djlint",
"categories": ["linter", "formatter"],
"categories": ["formatter", "linter"],
"commands": {
"": ["$PATH", "--reformat"]
},
Expand Down
2 changes: 1 addition & 1 deletion tools/easy-coding-standard/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../tool.schema.json",
"binary": "ecs",
"categories": ["linter", "formatter"],
"categories": ["formatter", "linter"],
"commands": {
"": ["check", "$PATH", "--fix", "--no-interaction"]
},
Expand Down
2 changes: 1 addition & 1 deletion tools/joker/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../tool.schema.json",
"binary": "joker",
"categories": ["linter", "formatter"],
"categories": ["formatter", "linter"],
"commands": {
"": ["--format", "--write", "$PATH"]
},
Expand Down
17 changes: 17 additions & 0 deletions tools/shellharden/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "../tool.schema.json",

"binary": "shellharden",

"commands": {
"": ["--transform", "--replace", "$PATH"]
},
"languages": ["bash", "shell"],
"categories": ["linter"],
"description": "The corrective bash syntax highlighter",
"homepage": "https://github.com/anordal/shellharden",
"name": null,
"tests": [],
"npm": null,
"php": null
}
Loading