From 604e0a953018a0e103c429a05e83f94d3fbb9a89 Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 12 Jan 2025 19:15:14 +0100 Subject: [PATCH] feat: add support for quick-lint-js --- CHANGELOG.md | 1 + README.md | 3 ++- mdsf/src/tools/mod.rs | 7 ++++++ mdsf/src/tools/quick_lint_js.rs | 38 +++++++++++++++++++++++++++++ schemas/v0.3.3-dev/mdsf.schema.json | 5 ++++ tools/quick-lint-js/plugin.json | 15 ++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 mdsf/src/tools/quick_lint_js.rs create mode 100644 tools/quick-lint-js/plugin.json diff --git a/CHANGELOG.md b/CHANGELOG.md index efd8e02..b632b02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 quick-lint-js [`#599`](https://github.com/hougesen/mdsf/pull/599) - feat: add support for oelint-adv [`#598`](https://github.com/hougesen/mdsf/pull/598) - feat: add support for mypy [`#597`](https://github.com/hougesen/mdsf/pull/597) - feat: add support for luacheck [`#596`](https://github.com/hougesen/mdsf/pull/596) diff --git a/README.md b/README.md index b5240fc..5f7cff6 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ mdsf init -`mdsf` currently supports 230 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 +`mdsf` currently supports 231 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃 | Name | Description | Categories | Languages | | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- | @@ -379,6 +379,7 @@ mdsf init | [pyink](https://github.com/google/pyink) | Pyink is a Python formatter, forked from Black with a few different formatting behaviors | `formatter` | `python` | | [pyment](https://github.com/dadadel/pyment) | Format and convert Python docstrings and generates patches | `formatter` | `python` | | [qmlfmt](https://github.com/jesperhh/qmlfmt) | qmlfmt - command line application that formats QML files | `formatter` | `qml` | +| [quick-lint-js](https://github.com/quick-lint/quick-lint-js) | quick-lint-js finds bugs in JavaScript programs | `linter` | `javascript` | | [raco](https://docs.racket-lang.org/fmt/) | An extensible code formatter for Racket | `formatter` | `racket` | | [refmt](https://reasonml.github.io/docs/en/refmt) | refmt stands by Reason Formatter and it formats Reason programs, is a parser and pretty-printer for Reason | `formatter` | `reason` | | [reformat-gherkin](https://github.com/ducminh-phan/reformat-gherkin) | Reformat-gherkin automatically formats Gherkin files | `formatter` | `gherkin` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index 9de8014..bcc9dbc 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -166,6 +166,7 @@ pub mod pycln; pub mod pyink; pub mod pyment; pub mod qmlfmt; +pub mod quick_lint_js; pub mod raco_fmt; pub mod refmt; pub mod reformat_gherkin; @@ -915,6 +916,10 @@ pub enum Tooling { /// `qmlfmt -w $PATH` Qmlfmt, + #[serde(rename = "quick-lint-js")] + /// `quick-lint-js $PATH` + QuickLintJs, + #[serde(rename = "raco:fmt")] /// `raco fmt -i $PATH` RacoFmt, @@ -1380,6 +1385,7 @@ impl Tooling { Self::Pyink => pyink::run(snippet_path), Self::Pyment => pyment::run(snippet_path), Self::Qmlfmt => qmlfmt::run(snippet_path), + Self::QuickLintJs => quick_lint_js::run(snippet_path), Self::RacoFmt => raco_fmt::run(snippet_path), Self::Refmt => refmt::run(snippet_path), Self::ReformatGherkin => reformat_gherkin::run(snippet_path), @@ -1629,6 +1635,7 @@ impl AsRef for Tooling { Self::Pyink => "pyink", Self::Pyment => "pyment", Self::Qmlfmt => "qmlfmt", + Self::QuickLintJs => "quick_lint_js", Self::RacoFmt => "raco_fmt", Self::Refmt => "refmt", Self::ReformatGherkin => "reformat_gherkin", diff --git a/mdsf/src/tools/quick_lint_js.rs b/mdsf/src/tools/quick_lint_js.rs new file mode 100644 index 0000000..a803819 --- /dev/null +++ b/mdsf/src/tools/quick_lint_js.rs @@ -0,0 +1,38 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_quick_lint_js_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), MdsfError> { + let commands = [ + CommandType::NodeModules("quick-lint-js"), + CommandType::Direct("quick-lint-js"), + CommandType::Npm("quick-lint-js"), + ]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_quick_lint_js_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_quick_lint_js {} diff --git a/schemas/v0.3.3-dev/mdsf.schema.json b/schemas/v0.3.3-dev/mdsf.schema.json index 63827db..a4e7600 100644 --- a/schemas/v0.3.3-dev/mdsf.schema.json +++ b/schemas/v0.3.3-dev/mdsf.schema.json @@ -898,6 +898,11 @@ "type": "string", "enum": ["qmlfmt"] }, + { + "description": "`quick-lint-js $PATH`", + "type": "string", + "enum": ["quick-lint-js"] + }, { "description": "`raco fmt -i $PATH`", "type": "string", diff --git a/tools/quick-lint-js/plugin.json b/tools/quick-lint-js/plugin.json new file mode 100644 index 0000000..4a6720f --- /dev/null +++ b/tools/quick-lint-js/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "quick-lint-js", + "categories": ["linter"], + "commands": { + "": ["$PATH"] + }, + "description": "quick-lint-js finds bugs in JavaScript programs", + "homepage": "https://github.com/quick-lint/quick-lint-js", + "languages": ["javascript"], + "name": null, + "npm": "quick-lint-js", + "php": null, + "tests": [] +}