Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for cmake-format #584

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 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 cmake-format [`#584`](https://github.com/hougesen/mdsf/pull/584)
- feat: nushell shell completion [`#583`](https://github.com/hougesen/mdsf/pull/583)
- feat: add support for ansible-lint [`#582`](https://github.com/hougesen/mdsf/pull/582)
- feat: add support for actionlint [`#581`](https://github.com/hougesen/mdsf/pull/581)
Expand All @@ -30,6 +31,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- build: update cargo-dist to v0.27.0 [`#558`](https://github.com/hougesen/mdsf/pull/558)
- build: update cargo-dist to v0.26.1 [`#557`](https://github.com/hougesen/mdsf/pull/557)
- chore: update dev version to v0.3.3-dev [`#556`](https://github.com/hougesen/mdsf/pull/556)
- feat: nushell shell completion (#583) [`#382`](https://github.com/hougesen/mdsf/issues/382)

#### [v0.3.2](https://github.com/hougesen/mdsf/compare/v0.3.1...v0.3.2)

Expand Down
5 changes: 3 additions & 2 deletions 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 215 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃
`mdsf` currently supports 216 tools. Feel free to open an issue/pull-request if your favorite tool/command is missing! 😃

| Name | Description | Categories | Languages |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------- |
Expand Down Expand Up @@ -252,6 +252,7 @@ mdsf init
| [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) | clang-tidy is a clang-based C++ “linter” tool | `linter` | `c++` |
| [cljfmt](https://github.com/weavejester/cljfmt) | A tool for formatting Clojure code | `formatter` | `clojure` |
| [cljstyle](https://github.com/greglook/cljstyle) | A tool for formatting Clojure code | `formatter` | `clojure` |
| [cmake-format](https://cmake-format.readthedocs.io/en/latest/cmake-format.html) | cmake-format can format your listfiles nicely so that they don’t look like crap | `formatter` | `cmake` |
| [codespell](https://github.com/codespell-project/codespell) | Check code for common misspellings | `autocorrection` | |
| [crlfmt](https://github.com/cockroachdb/crlfmt) | Formatter for CockroachDB's additions to the Go style guide | `formatter` | `go` |
| [crystal](https://crystal-lang.org/) | Tools for the Crystal programming language | `formatter` | `crystal` |
Expand Down Expand Up @@ -319,7 +320,7 @@ mdsf init
| [kdoc-formatter](https://github.com/tnorbye/kdoc-formatter) | Reformats Kotlin KDoc comments, reflowing text and other cleanup | `formatter` | `kotlin` |
| [ktfmt](https://github.com/facebook/ktfmt) | program that reformats Kotlin source code to comply with the common community standard for Kotlin code conventions | `formatter` | `kotlin` |
| [ktlint](https://github.com/pinterest/ktlint) | An anti-bikeshedding Kotlin linter with built-in formatter | `linter` | `kotlin` |
| [kulala-fmt](https://github.com/mistweaverco/kulala-fmt) | An opinionated 🦄 .http and .rest 🐼 files linter 💄 and formatter ⚡. | `formatter` | `http` |
| [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` |
| [luaformatter](https://github.com/Koihik/LuaFormatter) | Code formatter for Lua | `formatter` | `lua` |
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/cmake_format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::process::Command;

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

#[inline]
fn set_cmake_format_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::Direct("cmake-format")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_cmake_format_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_cmake_format {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod clang_format;
pub mod clang_tidy;
pub mod cljfmt_fix;
pub mod cljstyle;
pub mod cmake_format;
pub mod codespell;
pub mod crlfmt;
pub mod crystal_format;
Expand Down Expand Up @@ -371,6 +372,10 @@ pub enum Tooling {
/// `cljstyle fix $PATH`
Cljstyle,

#[serde(rename = "cmake-format")]
/// `cmake-format -i $PATH`
CmakeFormat,

#[serde(rename = "codespell")]
/// `codespell $PATH --check-hidden --write-changes`
Codespell,
Expand Down Expand Up @@ -1168,6 +1173,7 @@ impl Tooling {
Self::ClangTidy => clang_tidy::run(snippet_path),
Self::CljfmtFix => cljfmt_fix::run(snippet_path),
Self::Cljstyle => cljstyle::run(snippet_path),
Self::CmakeFormat => cmake_format::run(snippet_path),
Self::Codespell => codespell::run(snippet_path),
Self::Crlfmt => crlfmt::run(snippet_path),
Self::CrystalFormat => crystal_format::run(snippet_path),
Expand Down Expand Up @@ -1401,6 +1407,7 @@ impl AsRef<str> for Tooling {
Self::ClangTidy => "clang_tidy",
Self::CljfmtFix => "cljfmt_fix",
Self::Cljstyle => "cljstyle",
Self::CmakeFormat => "cmake_format",
Self::Codespell => "codespell",
Self::Crlfmt => "crlfmt",
Self::CrystalFormat => "crystal_format",
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 @@ -238,6 +238,11 @@
"type": "string",
"enum": ["cljstyle"]
},
{
"description": "`cmake-format -i $PATH`",
"type": "string",
"enum": ["cmake-format"]
},
{
"description": "`codespell $PATH --check-hidden --write-changes`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/cmake-format/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "cmake-format",
"categories": ["formatter"],
"commands": {
"": ["-i", "$PATH"]
},
"description": "cmake-format can format your listfiles nicely so that they don’t look like crap",
"homepage": "https://cmake-format.readthedocs.io/en/latest/cmake-format.html",
"languages": ["cmake"],
"name": null,
"npm": null,
"php": null,
"tests": []
}
2 changes: 1 addition & 1 deletion tools/kulala-fmt/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"commands": {
"": ["$PATH"]
},
"description": "An opinionated 🦄 .http and .rest 🐼 files linter 💄 and formatter ⚡.",
"description": "An opinionated 🦄 .http and .rest 🐼 files linter 💄 and formatter ⚡",
"homepage": "https://github.com/mistweaverco/kulala-fmt",
"languages": ["http"],
"name": null,
Expand Down
Loading