Skip to content

Commit

Permalink
feat: support clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jun 15, 2024
1 parent fba28a1 commit d862f5b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mdsf init
<!-- START_SECTION:supported-languages -->

`mdsf` currently supports 119 tools.
`mdsf` currently supports 120 tools.

| Formatter | Description |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -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) |
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.1.1/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/formatters/clang_tidy.rs
Original file line number Diff line number Diff line change
@@ -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<String>), MdsfError> {
let mut cmd = std::process::Command::new("clang-tidy");

cmd.arg("--fix").arg(file_path);

execute_command(&mut cmd, file_path)
}
24 changes: 16 additions & 8 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -88,6 +89,7 @@ mod buf;
mod buildifier;
mod cabal_format;
mod clang_format;
mod clang_tidy;
mod cljstyle;
mod codespell;
mod crlfmt;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit d862f5b

Please sign in to comment.