From d862f5bd0bbff59b3c810148854d1b9999dbf46c Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 16 Jun 2024 00:47:43 +0200 Subject: [PATCH] feat: support clang-tidy --- README.md | 3 ++- schemas/v0.1.1/mdsf.schema.json | 5 +++++ src/formatters/clang_tidy.rs | 13 +++++++++++++ src/formatters/mod.rs | 24 ++++++++++++++++-------- 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/formatters/clang_tidy.rs diff --git a/README.md b/README.md index 1f2d5d28..b7a107cb 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ mdsf init -`mdsf` currently supports 119 tools. +`mdsf` currently supports 120 tools. | Formatter | Description | | ------------------ | ---------------------------------------------------------------------------------------------------------------------- | @@ -126,6 +126,7 @@ mdsf init | buildifier | [https://github.com/bazelbuild/buildtools](https://github.com/bazelbuild/buildtools) | | cabal_format | [https://www.haskell.org/cabal/](https://www.haskell.org/cabal/) | | clang-format | [https://docs.kernel.org/process/clang-format.html](https://docs.kernel.org/process/clang-format.html) | +| clang-tidy | [https://clang.llvm.org/extra/clang-tidy](https://clang.llvm.org/extra/clang-tidy) | | cljstyle | [https://github.com/greglook/cljstyle](https://github.com/greglook/cljstyle) | | codespell | [https://github.com/codespell-project/codespell](https://github.com/codespell-project/codespell) | | crlfmt | [https://github.com/cockroachdb/crlfmt](https://github.com/cockroachdb/crlfmt) | diff --git a/schemas/v0.1.1/mdsf.schema.json b/schemas/v0.1.1/mdsf.schema.json index 9a24d5ba..a0a7ca03 100644 --- a/schemas/v0.1.1/mdsf.schema.json +++ b/schemas/v0.1.1/mdsf.schema.json @@ -139,6 +139,11 @@ "type": "string", "enum": ["clang-format"] }, + { + "description": "https://clang.llvm.org/extra/clang-tidy", + "type": "string", + "enum": ["clang-tidy"] + }, { "description": "https://github.com/greglook/cljstyle", "type": "string", diff --git a/src/formatters/clang_tidy.rs b/src/formatters/clang_tidy.rs new file mode 100644 index 00000000..43f1f90c --- /dev/null +++ b/src/formatters/clang_tidy.rs @@ -0,0 +1,13 @@ +use super::execute_command; +use crate::error::MdsfError; + +#[inline] +pub fn format_using_clang_tidy( + file_path: &std::path::Path, +) -> Result<(bool, Option), MdsfError> { + let mut cmd = std::process::Command::new("clang-tidy"); + + cmd.arg("--fix").arg(file_path); + + execute_command(&mut cmd, file_path) +} diff --git a/src/formatters/mod.rs b/src/formatters/mod.rs index b0f6b7be..965582ba 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -15,14 +15,15 @@ use crate::{ black::format_using_black, blade_formatter::format_using_blade_formatter, blue::format_using_blue, bpfmt::format_using_bpfmt, buf::format_using_buf, buildifier::format_using_buildifier, cabal_format::format_using_cabal_format, - clang_format::format_using_clang_format, cljstyle::format_using_cljstyle, - codespell::format_using_codespell, crlfmt::format_using_crlfmt, - crystal_format::format_using_crystal_format, csharpier::format_using_csharpier, - d2::format_using_d2, dart_format::format_using_dart_format, - deno_fmt::format_using_deno_fmt, dfmt::format_using_dfmt, djlint::format_using_djlint, - docstrfmt::format_using_docstrfmt, dprint::format_using_dprint, efmt::format_using_efmt, - elm_format::format_using_elm_format, erb_formatter::format_using_erb_formatter, - erlfmt::format_using_erlfmt, eslint::format_using_eslint, fantomas::format_using_fantomas, + clang_format::format_using_clang_format, clang_tidy::format_using_clang_tidy, + cljstyle::format_using_cljstyle, codespell::format_using_codespell, + crlfmt::format_using_crlfmt, crystal_format::format_using_crystal_format, + csharpier::format_using_csharpier, d2::format_using_d2, + dart_format::format_using_dart_format, deno_fmt::format_using_deno_fmt, + dfmt::format_using_dfmt, djlint::format_using_djlint, docstrfmt::format_using_docstrfmt, + dprint::format_using_dprint, efmt::format_using_efmt, elm_format::format_using_elm_format, + erb_formatter::format_using_erb_formatter, erlfmt::format_using_erlfmt, + eslint::format_using_eslint, fantomas::format_using_fantomas, findent::format_using_findent, fish_indent::format_using_fish_indent, fixjson::format_using_fixjson, fnlfmt::format_using_fnlfmt, forge_fmt::format_using_forge_fmt, fourmolu::format_using_fourmolu, @@ -88,6 +89,7 @@ mod buf; mod buildifier; mod cabal_format; mod clang_format; +mod clang_tidy; mod cljstyle; mod codespell; mod crlfmt; @@ -380,6 +382,10 @@ pub enum Tooling { #[serde(rename = "clang-format")] ClangFormat, + #[doc = "https://clang.llvm.org/extra/clang-tidy"] + #[serde(rename = "clang-tidy")] + ClangTidy, + #[doc = "https://github.com/greglook/cljstyle"] #[serde(rename = "cljstyle")] Cljstyle, @@ -813,6 +819,7 @@ impl Tooling { Self::CSharpier => format_using_csharpier(snippet_path), Self::CabalFormat => format_using_cabal_format(snippet_path), Self::ClangFormat => format_using_clang_format(snippet_path), + Self::ClangTidy => format_using_clang_tidy(snippet_path), Self::Cljstyle => format_using_cljstyle(snippet_path), Self::Codespell => format_using_codespell(snippet_path), Self::CrlFmt => format_using_crlfmt(snippet_path), @@ -941,6 +948,7 @@ impl core::fmt::Display for Tooling { Self::CSharpier => write!(f, "csharpier"), Self::CabalFormat => write!(f, "cabal_format"), Self::ClangFormat => write!(f, "clang-format"), + Self::ClangTidy => write!(f, "clang-tidy"), Self::Cljstyle => write!(f, "cljstyle"), Self::Codespell => write!(f, "codespell"), Self::CrlFmt => write!(f, "crlfmt"),