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 bslint #506

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
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 196 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 197 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand All @@ -209,6 +209,7 @@ mdsf init
| `brittany` | `brittany --write-mode=inplace PATH` |
| `brunette` | `brunette --quiet PATH` |
| `bsfmt` | `bsfmt PATH --write` |
| `bslint` | `bslint --fix PATH` |
| `buf:format` | `buf format --write PATH` |
| `buildifier` | `buildifier PATH` |
| `cabal:format` | `cabal format PATH` |
Expand Down
39 changes: 39 additions & 0 deletions mdsf/src/tools/bslint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::process::Command;

use crate::{error::MdsfError, execution::execute_command, runners::CommandType};

#[inline]
fn set_bslint_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
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::NodeModules("bslint"),
CommandType::Direct("bslint"),
CommandType::Npm("bslint"),
];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_bslint_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_bslint {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod bpfmt;
pub mod brittany;
pub mod brunette;
pub mod bsfmt;
pub mod bslint;
pub mod buf_format;
pub mod buildifier;
pub mod cabal_format;
Expand Down Expand Up @@ -283,6 +284,10 @@ pub enum Tooling {
/// `bsfmt $PATH --write`
Bsfmt,

#[serde(rename = "bslint")]
/// `bslint --fix $PATH`
Bslint,

#[serde(rename = "buf:format")]
/// `buf format --write $PATH`
BufFormat,
Expand Down Expand Up @@ -1013,6 +1018,7 @@ impl Tooling {
Self::Brittany => brittany::run(snippet_path),
Self::Brunette => brunette::run(snippet_path),
Self::Bsfmt => bsfmt::run(snippet_path),
Self::Bslint => bslint::run(snippet_path),
Self::BufFormat => buf_format::run(snippet_path),
Self::Buildifier => buildifier::run(snippet_path),
Self::CabalFormat => cabal_format::run(snippet_path),
Expand Down Expand Up @@ -1218,6 +1224,7 @@ impl AsRef<str> for Tooling {
Self::Brittany => "brittany",
Self::Brunette => "brunette",
Self::Bsfmt => "bsfmt",
Self::Bslint => "bslint",
Self::BufFormat => "buf_format",
Self::Buildifier => "buildifier",
Self::CabalFormat => "cabal_format",
Expand Down
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 @@ -163,6 +163,11 @@
"type": "string",
"enum": ["bsfmt"]
},
{
"description": "`bslint --fix $PATH`",
"type": "string",
"enum": ["bslint"]
},
{
"description": "`buf format --write $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/bslint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"binary": "bslint",
"homepage": "https://github.com/rokucommunity/bslint",
"$schema": "../tool.schema.json",
"categories": ["linter"],
"languages": ["brightscript", "brightscripter"],
"npm": "bslint",
"php": null,
"name": null,
"tests": [],
"commands": {
"": ["--fix", "$PATH"]
},
"description": "A linter for BrightScript and BrighterScript"
}
Loading