From a338bc2270116069bf8e54c1420d1a27b658fc04 Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 16 Jun 2024 01:58:20 +0200 Subject: [PATCH] feat: support dcm (#300) --- README.md | 3 ++- schemas/v0.1.1/mdsf.schema.json | 5 +++++ src/formatters/dcm.rs | 11 +++++++++++ src/formatters/mod.rs | 11 +++++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/formatters/dcm.rs diff --git a/README.md b/README.md index e8d4f899..4698d4e4 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ mdsf init -`mdsf` currently supports 126 tools. +`mdsf` currently supports 127 tools. | Formatter | Description | | ------------------ | ---------------------------------------------------------------------------------------------------------------------- | @@ -134,6 +134,7 @@ mdsf init | csharpier | [https://csharpier.com/](https://csharpier.com/) | | d2 | [https://d2lang.com/](https://d2lang.com/) | | dart_format | [https://dart.dev/tools/dart-format](https://dart.dev/tools/dart-format) | +| dcm | [https://dcm.dev](https://dcm.dev) | | deno_fmt | [https://dart.dev/tools/dart-format](https://dart.dev/tools/dart-format) | | dfmt | [https://github.com/dlang-community/dfmt](https://github.com/dlang-community/dfmt) | | djlint | [https://www.djlint.com/](https://www.djlint.com/) | diff --git a/schemas/v0.1.1/mdsf.schema.json b/schemas/v0.1.1/mdsf.schema.json index dbe4ae08..920302b9 100644 --- a/schemas/v0.1.1/mdsf.schema.json +++ b/schemas/v0.1.1/mdsf.schema.json @@ -179,6 +179,11 @@ "type": "string", "enum": ["dart_format"] }, + { + "description": "https://dcm.dev", + "type": "string", + "enum": ["dcm"] + }, { "description": "https://dart.dev/tools/dart-format", "type": "string", diff --git a/src/formatters/dcm.rs b/src/formatters/dcm.rs new file mode 100644 index 00000000..0dc2d484 --- /dev/null +++ b/src/formatters/dcm.rs @@ -0,0 +1,11 @@ +use super::execute_command; +use crate::error::MdsfError; + +#[inline] +pub fn format_using_dcm(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let mut cmd = std::process::Command::new("dcm"); + + 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 04946628..9f9fb062 100644 --- a/src/formatters/mod.rs +++ b/src/formatters/mod.rs @@ -19,8 +19,8 @@ use crate::{ 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, + dart_format::format_using_dart_format, dcm::format_using_dcm, + deno_fmt::format_using_deno_fmt, dfmt::format_using_dfmt, djlint::format_using_djlint, docformatter::format_using_docformatter, 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, @@ -100,6 +100,7 @@ mod crystal_format; mod csharpier; mod d2; mod dart_format; +mod dcm; mod deno_fmt; mod dfmt; mod djlint; @@ -423,6 +424,10 @@ pub enum Tooling { #[serde(rename = "dart_format")] DartFormat, + #[doc = "https://dcm.dev"] + #[serde(rename = "dcm")] + Dcm, + #[doc = "https://dart.dev/tools/dart-format"] #[serde(rename = "deno_fmt")] DenoFmt, @@ -860,6 +865,7 @@ impl Tooling { Self::D2 => format_using_d2(snippet_path), Self::DFmt => format_using_dfmt(snippet_path), Self::DartFormat => format_using_dart_format(snippet_path), + Self::Dcm => format_using_dcm(snippet_path), Self::DenoFmt => format_using_deno_fmt(snippet_path), Self::DjLint => format_using_djlint(snippet_path), Self::Docformatter => format_using_docformatter(snippet_path), @@ -997,6 +1003,7 @@ impl core::fmt::Display for Tooling { Self::DartFormat => write!(f, "dart_format"), Self::DenoFmt => write!(f, "deno_fmt"), Self::DjLint => write!(f, "djlint"), + Self::Dcm => write!(f, "dcm"), Self::Docformatter => write!(f, "docformatter"), Self::Docstrfmt => write!(f, "docstrfmt"), Self::Dprint => write!(f, "dprint"),