Skip to content

Commit

Permalink
feat: support protolint (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Oct 26, 2024
1 parent ad06b5a commit 290797e
Show file tree
Hide file tree
Showing 6 changed files with 66 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.2.7...HEAD)

- feat: support protolint [`#509`](https://github.com/hougesen/mdsf/pull/509)
- feat: support jsonlint [`#508`](https://github.com/hougesen/mdsf/pull/508)
- feat: support hlint [`#507`](https://github.com/hougesen/mdsf/pull/507)
- feat: support bslint [`#506`](https://github.com/hougesen/mdsf/pull/506)
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 199 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 200 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -318,6 +318,7 @@ mdsf init
| `prettier` | `prettier --embedded-language-formatting off --log-level error --write PATH` |
| `pretty-php` | `pretty-php PATH` |
| `prettypst` | `prettypst PATH` |
| `protolint` | `protolint lint -fix PATH` |
| `puppet-lint` | `puppet-lint --fix PATH` |
| `purs-tidy` | `purs-tidy format-in-place PATH` |
| `pycln` | `pycln --no-gitignore --quiet 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 @@ -128,6 +128,7 @@ pub mod pint;
pub mod prettier;
pub mod pretty_php;
pub mod prettypst;
pub mod protolint;
pub mod puppet_lint;
pub mod purs_tidy;
pub mod pycln;
Expand Down Expand Up @@ -722,6 +723,10 @@ pub enum Tooling {
/// `prettypst $PATH`
Prettypst,

#[serde(rename = "protolint")]
/// `protolint lint -fix $PATH`
Protolint,

#[serde(rename = "puppet-lint")]
/// `puppet-lint --fix $PATH`
PuppetLint,
Expand Down Expand Up @@ -1137,6 +1142,7 @@ impl Tooling {
Self::Prettier => prettier::run(snippet_path),
Self::PrettyPhp => pretty_php::run(snippet_path),
Self::Prettypst => prettypst::run(snippet_path),
Self::Protolint => protolint::run(snippet_path),
Self::PuppetLint => puppet_lint::run(snippet_path),
Self::PursTidy => purs_tidy::run(snippet_path),
Self::Pycln => pycln::run(snippet_path),
Expand Down Expand Up @@ -1345,6 +1351,7 @@ impl AsRef<str> for Tooling {
Self::Prettier => "prettier",
Self::PrettyPhp => "pretty_php",
Self::Prettypst => "prettypst",
Self::Protolint => "protolint",
Self::PuppetLint => "puppet_lint",
Self::PursTidy => "purs_tidy",
Self::Pycln => "pycln",
Expand Down
36 changes: 36 additions & 0 deletions mdsf/src/tools/protolint.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_protolint_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("lint");
cmd.arg("-fix");
cmd.arg(file_path);
cmd
}

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

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_protolint_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_protolint {}
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 @@ -708,6 +708,11 @@
"type": "string",
"enum": ["prettypst"]
},
{
"description": "`protolint lint -fix $PATH`",
"type": "string",
"enum": ["protolint"]
},
{
"description": "`puppet-lint --fix $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/protolint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "protolint",
"categories": ["linter"],
"commands": {
"": ["lint", "-fix", "$PATH"]
},
"description": "A pluggable linter and fixer to enforce Protocol Buffer style and conventions",
"homepage": "https://github.com/yoheimuta/protolint",
"languages": ["protobuf"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 290797e

Please sign in to comment.