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 ansible-lint #582

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 ansible-lint [`#582`](/~https://github.com/hougesen/mdsf/pull/582)
- feat: add support for actionlint [`#581`](/~https://github.com/hougesen/mdsf/pull/581)
- feat: add support for tex-fmt [`#580`](/~https://github.com/hougesen/mdsf/pull/580)
- build(deps): bump console from 0.15.8 to 0.15.10 [`#565`](/~https://github.com/hougesen/mdsf/pull/565)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,14 @@ mdsf init

<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 214 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 215 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
| [actionlint](/~https://github.com/rhysd/actionlint) | Static checker for GitHub Actions workflow files | `linter` | `yaml` |
| [alejandra](/~https://github.com/kamadorueda/alejandra) | The Uncompromising Nix Code Formatter | `formatter` | `nix` |
| [ameba](/~https://github.com/crystal-ameba/ameba) | A static code analysis tool for Crystal | `linter` | `crystal` |
| [ansible-lint](/~https://github.com/ansible/ansible-lint) | ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you | `linter` | `ansible` |
| [asmfmt](/~https://github.com/klauspost/asmfmt) | Go Assembler Formatter | `formatter` | `go` |
| [astyle](https://gitlab.com/saalen/astyle) | A Free, Fast, and Small Automatic Formatter for C, C++, C++/CLI, Objective-C, C#, and Java Source Code | `formatter` | `c#`, `c++`, `c`, `java`, `objective-c` |
| [auto-optional](/~https://github.com/Luttik/auto-optional) | Adds the Optional type-hint to arguments where the default value is None | `formatter` | `python` |
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/ansible_lint.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_ansible_lint_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("ansible-lint")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_ansible_lint_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_ansible_lint {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod actionlint;
pub mod alejandra;
pub mod ameba;
pub mod ansible_lint;
pub mod asmfmt;
pub mod astyle;
pub mod auto_optional;
Expand Down Expand Up @@ -238,6 +239,10 @@ pub enum Tooling {
/// `ameba --fix $PATH`
Ameba,

#[serde(rename = "ansible-lint")]
/// `ansible-lint $PATH`
AnsibleLint,

#[serde(rename = "asmfmt")]
/// `asmfmt -w $PATH`
Asmfmt,
Expand Down Expand Up @@ -1130,6 +1135,7 @@ impl Tooling {
Self::Actionlint => actionlint::run(snippet_path),
Self::Alejandra => alejandra::run(snippet_path),
Self::Ameba => ameba::run(snippet_path),
Self::AnsibleLint => ansible_lint::run(snippet_path),
Self::Asmfmt => asmfmt::run(snippet_path),
Self::Astyle => astyle::run(snippet_path),
Self::AutoOptional => auto_optional::run(snippet_path),
Expand Down Expand Up @@ -1362,6 +1368,7 @@ impl AsRef<str> for Tooling {
Self::Actionlint => "actionlint",
Self::Alejandra => "alejandra",
Self::Ameba => "ameba",
Self::AnsibleLint => "ansible_lint",
Self::Asmfmt => "asmfmt",
Self::Astyle => "astyle",
Self::AutoOptional => "auto_optional",
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 @@ -73,6 +73,11 @@
"type": "string",
"enum": ["ameba"]
},
{
"description": "`ansible-lint $PATH`",
"type": "string",
"enum": ["ansible-lint"]
},
{
"description": "`asmfmt -w $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/ansible-lint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "ansible-lint",
"categories": ["linter"],
"commands": {
"": ["$PATH"]
},
"description": "ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you",
"homepage": "/~https://github.com/ansible/ansible-lint",
"languages": ["ansible"],
"name": null,
"npm": null,
"php": null,
"tests": []
}
Loading