Skip to content

Commit

Permalink
feat: support tsqllint
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Oct 27, 2024
1 parent 9adaf7f commit 8f15220
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 tsqllint [`#519`](https://github.com/hougesen/mdsf/pull/519)
- feat: support pyment [`#518`](https://github.com/hougesen/mdsf/pull/518)
- feat: support sqruff [`#517`](https://github.com/hougesen/mdsf/pull/517)
- feat: support opa fmt [`#516`](https://github.com/hougesen/mdsf/pull/516)
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 209 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 210 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -376,6 +376,7 @@ mdsf init
| `tofu:fmt` | `tofu fmt -write=true PATH` |
| `topiary` | `topiary format PATH` |
| `ts-standard` | `ts-standard --fix PATH` |
| `tsqllint` | `tsqllint --fix PATH` |
| `twig-cs-fixer:lint` | `twig-cs-fixer lint PATH --fix --no-interaction --quiet` |
| `typos` | `typos -w --no-ignore --hidden PATH` |
| `typstfmt` | `typstfmt 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 @@ -186,6 +186,7 @@ pub mod tlint_format;
pub mod tofu_fmt;
pub mod topiary;
pub mod ts_standard;
pub mod tsqllint;
pub mod twig_cs_fixer_lint;
pub mod typos;
pub mod typstfmt;
Expand Down Expand Up @@ -964,6 +965,10 @@ pub enum Tooling {
/// `ts-standard --fix $PATH`
TsStandard,

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

#[serde(rename = "twig-cs-fixer:lint")]
/// `twig-cs-fixer lint $PATH --fix --no-interaction --quiet`
TwigCsFixerLint,
Expand Down Expand Up @@ -1245,6 +1250,7 @@ impl Tooling {
Self::TofuFmt => tofu_fmt::run(snippet_path),
Self::Topiary => topiary::run(snippet_path),
Self::TsStandard => ts_standard::run(snippet_path),
Self::Tsqllint => tsqllint::run(snippet_path),
Self::TwigCsFixerLint => twig_cs_fixer_lint::run(snippet_path),
Self::Typos => typos::run(snippet_path),
Self::Typstfmt => typstfmt::run(snippet_path),
Expand Down Expand Up @@ -1463,6 +1469,7 @@ impl AsRef<str> for Tooling {
Self::TofuFmt => "tofu_fmt",
Self::Topiary => "topiary",
Self::TsStandard => "ts_standard",
Self::Tsqllint => "tsqllint",
Self::TwigCsFixerLint => "twig_cs_fixer_lint",
Self::Typos => "typos",
Self::Typstfmt => "typstfmt",
Expand Down
39 changes: 39 additions & 0 deletions mdsf/src/tools/tsqllint.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_tsqllint_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("tsqllint"),
CommandType::Direct("tsqllint"),
CommandType::Npm("tsqllint"),
];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_tsqllint_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_tsqllint {}
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 @@ -998,6 +998,11 @@
"type": "string",
"enum": ["ts-standard"]
},
{
"description": "`tsqllint --fix $PATH`",
"type": "string",
"enum": ["tsqllint"]
},
{
"description": "`twig-cs-fixer lint $PATH --fix --no-interaction --quiet`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/tsqllint/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "tsqllint",
"categories": ["linter"],
"commands": {
"": ["--fix", "$PATH"]
},
"description": "Configurable linting for TSQL",
"homepage": "https://github.com/tsqllint/tsqllint",
"languages": ["sql"],
"name": null,
"npm": "tsqllint",
"php": null,
"tests": []
}

0 comments on commit 8f15220

Please sign in to comment.