Skip to content

Commit

Permalink
feat: support kdoc-formatter (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Oct 27, 2024
1 parent d2ed0fc commit 4b59f4d
Show file tree
Hide file tree
Showing 6 changed files with 65 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 kdoc-formatter [`#521`](https://github.com/hougesen/mdsf/pull/521)
- feat: support djade [`#520`](https://github.com/hougesen/mdsf/pull/520)
- feat: support tsqllint [`#519`](https://github.com/hougesen/mdsf/pull/519)
- feat: support pyment [`#518`](https://github.com/hougesen/mdsf/pull/518)
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 211 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 212 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -288,6 +288,7 @@ mdsf init
| `just` | `just --fmt --unstable --justfile PATH` |
| `kcl:fmt` | `kcl fmt PATH` |
| `kdlfmt` | `kdlfmt format PATH` |
| `kdoc-formatter` | `kdoc-formatter --quiet PATH` |
| `ktfmt` | `ktfmt --format --log-level=error PATH` |
| `ktlint` | `ktlint --format --log-level=error PATH` |
| `kulala-fmt` | `kulala-fmt PATH` |
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/kdoc_formatter.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_kdoc_formatter_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("--quiet");
cmd.arg(file_path);
cmd
}

#[inline]
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let commands = [CommandType::Direct("kdoc-formatter")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_kdoc_formatter_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_kdoc_formatter {}
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub mod juliaformatter_jl;
pub mod just;
pub mod kcl_fmt;
pub mod kdlfmt;
pub mod kdoc_formatter;
pub mod ktfmt;
pub mod ktlint;
pub mod kulala_fmt;
Expand Down Expand Up @@ -614,6 +615,10 @@ pub enum Tooling {
/// `kdlfmt format $PATH`
Kdlfmt,

#[serde(rename = "kdoc-formatter")]
/// `kdoc-formatter --quiet $PATH`
KdocFormatter,

#[serde(rename = "ktfmt")]
/// `ktfmt --format --log-level=error $PATH`
Ktfmt,
Expand Down Expand Up @@ -1167,6 +1172,7 @@ impl Tooling {
Self::Just => just::run(snippet_path),
Self::KclFmt => kcl_fmt::run(snippet_path),
Self::Kdlfmt => kdlfmt::run(snippet_path),
Self::KdocFormatter => kdoc_formatter::run(snippet_path),
Self::Ktfmt => ktfmt::run(snippet_path),
Self::Ktlint => ktlint::run(snippet_path),
Self::KulalaFmt => kulala_fmt::run(snippet_path),
Expand Down Expand Up @@ -1387,6 +1393,7 @@ impl AsRef<str> for Tooling {
Self::Just => "just",
Self::KclFmt => "kcl_fmt",
Self::Kdlfmt => "kdlfmt",
Self::KdocFormatter => "kdoc_formatter",
Self::Ktfmt => "ktfmt",
Self::Ktlint => "ktlint",
Self::KulalaFmt => "kulala_fmt",
Expand Down
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 @@ -558,6 +558,11 @@
"type": "string",
"enum": ["kdlfmt"]
},
{
"description": "`kdoc-formatter --quiet $PATH`",
"type": "string",
"enum": ["kdoc-formatter"]
},
{
"description": "`ktfmt --format --log-level=error $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/kdoc-formatter/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "kdoc-formatter",
"categories": ["formatter"],
"commands": {
"": ["--quiet", "$PATH"]
},
"description": "Reformats Kotlin KDoc comments, reflowing text and other cleanup",
"homepage": "https://github.com/tnorbye/kdoc-formatter",
"languages": ["kotlin"],
"name": null,
"npm": null,
"php": null,
"tests": []
}

0 comments on commit 4b59f4d

Please sign in to comment.