Skip to content

Commit

Permalink
feat: add support for luacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jan 12, 2025
1 parent 4bc5c95 commit 0560f78
Show file tree
Hide file tree
Showing 6 changed files with 64 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.3.2...HEAD)

- feat: add support for luacheck [`#596`](https://github.com/hougesen/mdsf/pull/596)
- feat: add support for htmlhint [`#595`](https://github.com/hougesen/mdsf/pull/595)
- feat: add support for vacuum [`#594`](https://github.com/hougesen/mdsf/pull/594)
- feat: add support for hclfmt [`#593`](https://github.com/hougesen/mdsf/pull/593)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 227 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 228 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -329,6 +329,7 @@ mdsf init
| [kulala-fmt](https://github.com/mistweaverco/kulala-fmt) | An opinionated 🦄 .http and .rest 🐼 files linter 💄 and formatter ⚡ | `formatter` | `http` |
| [leptosfmt](https://github.com/bram209/leptosfmt) | A formatter for the leptos view! macro | `formatter` | `rust` |
| [liquidsoap-prettier](https://github.com/savonet/liquidsoap-prettier) | Prettier plugin for liquidsoap script | `formatter` | `liquidsoap` |
| [luacheck](https://github.com/lunarmodules/luacheck) | A tool for linting and static analysis of Lua code | `formatter` | `lua` |
| [luaformatter](https://github.com/Koihik/LuaFormatter) | Code formatter for Lua | `formatter` | `lua` |
| [markdownfmt](https://github.com/shurcooL/markdownfmt) | Like gofmt, but for Markdown | `formatter` | `markdown` |
| [markdownlint-cli2](https://github.com/davidanson/markdownlint-cli2) | A fast, flexible, configuration-based command-line interface for linting Markdown/CommonMark files with the markdownlint library | `linter` | `markdown` |
Expand Down
34 changes: 34 additions & 0 deletions mdsf/src/tools/luacheck.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::process::Command;

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

#[inline]
fn set_luacheck_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<String>), MdsfError> {
let commands = [CommandType::Direct("luacheck")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_luacheck_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_luacheck {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub mod ktlint;
pub mod kulala_fmt;
pub mod leptosfmt;
pub mod liquidsoap_prettier;
pub mod luacheck;
pub mod luaformatter;
pub mod markdownfmt;
pub mod markdownlint;
Expand Down Expand Up @@ -708,6 +709,10 @@ pub enum Tooling {
/// `liquidsoap-prettier --write $PATH`
LiquidsoapPrettier,

#[serde(rename = "luacheck")]
/// `luacheck $PATH`
Luacheck,

#[serde(rename = "luaformatter")]
/// `lua-format -i $PATH`
Luaformatter,
Expand Down Expand Up @@ -1314,6 +1319,7 @@ impl Tooling {
Self::KulalaFmt => kulala_fmt::run(snippet_path),
Self::Leptosfmt => leptosfmt::run(snippet_path),
Self::LiquidsoapPrettier => liquidsoap_prettier::run(snippet_path),
Self::Luacheck => luacheck::run(snippet_path),
Self::Luaformatter => luaformatter::run(snippet_path),
Self::Markdownfmt => markdownfmt::run(snippet_path),
Self::Markdownlint => markdownlint::run(snippet_path),
Expand Down Expand Up @@ -1560,6 +1566,7 @@ impl AsRef<str> for Tooling {
Self::KulalaFmt => "kulala_fmt",
Self::Leptosfmt => "leptosfmt",
Self::LiquidsoapPrettier => "liquidsoap_prettier",
Self::Luacheck => "luacheck",
Self::Luaformatter => "luaformatter",
Self::Markdownfmt => "markdownfmt",
Self::Markdownlint => "markdownlint",
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.3.3-dev/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@
"type": "string",
"enum": ["liquidsoap-prettier"]
},
{
"description": "`luacheck $PATH`",
"type": "string",
"enum": ["luacheck"]
},
{
"description": "`lua-format -i $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/luacheck/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "luacheck",
"categories": ["formatter"],
"commands": {
"": ["$PATH"]
},
"description": "A tool for linting and static analysis of Lua code",
"homepage": "https://github.com/lunarmodules/luacheck",
"languages": ["lua"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 0560f78

Please sign in to comment.