Skip to content

Commit

Permalink
feat: support jsonlint
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Oct 26, 2024
1 parent a04ac16 commit 81f8aa6
Show file tree
Hide file tree
Showing 6 changed files with 69 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 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)
- feat: support terragrunt hclfmt [`#505`](https://github.com/hougesen/mdsf/pull/505)
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 198 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 199 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -277,6 +277,7 @@ mdsf init
| `js-beautify` | `js-beautify -r --type js -f PATH` |
| `jsona:format` | `jsona format PATH` |
| `jsona:lint` | `jsona lint PATH` |
| `jsonlint` | `jsonlint -i PATH` |
| `jsonnetfmt` | `jsonnetfmt -i PATH` |
| `juliaformatter.jl` | `julia -E using JuliaFormatter;format_file(\"\")` |
| `just` | `just --fmt --unstable --justfile PATH` |
Expand Down
39 changes: 39 additions & 0 deletions mdsf/src/tools/jsonlint.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_jsonlint_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("-i");
cmd.arg(file_path);
cmd
}

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

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_jsonlint_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_jsonlint {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub mod joker;
pub mod js_beautify;
pub mod jsona_format;
pub mod jsona_lint;
pub mod jsonlint;
pub mod jsonnetfmt;
pub mod juliaformatter_jl;
pub mod just;
Expand Down Expand Up @@ -557,6 +558,10 @@ pub enum Tooling {
/// `jsona lint $PATH`
JsonaLint,

#[serde(rename = "jsonlint")]
/// `jsonlint -i $PATH`
Jsonlint,

#[serde(rename = "jsonnetfmt")]
/// `jsonnetfmt -i $PATH`
Jsonnetfmt,
Expand Down Expand Up @@ -1091,6 +1096,7 @@ impl Tooling {
Self::JsBeautify => js_beautify::run(snippet_path),
Self::JsonaFormat => jsona_format::run(snippet_path),
Self::JsonaLint => jsona_lint::run(snippet_path),
Self::Jsonlint => jsonlint::run(snippet_path),
Self::Jsonnetfmt => jsonnetfmt::run(snippet_path),
Self::JuliaformatterJl => juliaformatter_jl::run(snippet_path),
Self::Just => just::run(snippet_path),
Expand Down Expand Up @@ -1298,6 +1304,7 @@ impl AsRef<str> for Tooling {
Self::JsBeautify => "js_beautify",
Self::JsonaFormat => "jsona_format",
Self::JsonaLint => "jsona_lint",
Self::Jsonlint => "jsonlint",
Self::Jsonnetfmt => "jsonnetfmt",
Self::JuliaformatterJl => "juliaformatter_jl",
Self::Just => "just",
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 @@ -503,6 +503,11 @@
"type": "string",
"enum": ["jsona:lint"]
},
{
"description": "`jsonlint -i $PATH`",
"type": "string",
"enum": ["jsonlint"]
},
{
"description": "`jsonnetfmt -i $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/jsonlint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "jsonlint",
"categories": ["formatter", "linter"],
"commands": {
"": ["-i", "$PATH"]
},
"description": "A JSON parser and validator with a CLI",
"homepage": "https://github.com/zaach/jsonlint",
"languages": ["json"],
"name": null,
"npm": "jsonlint",
"php": null,
"tests": []
}

0 comments on commit 81f8aa6

Please sign in to comment.