Skip to content

Commit

Permalink
feat: support templ fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jun 15, 2024
1 parent 9929102 commit b4bade9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 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 118 tools.
`mdsf` currently supports 119 tools.

| Formatter | Description |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -214,6 +214,7 @@ mdsf init
| swift-format | [https://github.com/apple/swift-format](https://github.com/apple/swift-format) |
| swiftformat | [https://github.com/nicklockwood/SwiftFormat](https://github.com/nicklockwood/SwiftFormat) |
| taplo | [https://github.com/tamasfe/taplo](https://github.com/tamasfe/taplo) |
| templ | [https://templ.guide](https://templ.guide) |
| terraform_fmt | [https://www.terraform.io/docs/cli/commands/fmt.html](https://www.terraform.io/docs/cli/commands/fmt.html) |
| tofu_fmt | [https://opentofu.org/docs/cli/commands/fmt/](https://opentofu.org/docs/cli/commands/fmt/) |
| typos | [https://github.com/crate-ci/typos](https://github.com/crate-ci/typos) |
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 @@ -579,6 +579,11 @@
"type": "string",
"enum": ["taplo"]
},
{
"description": "https://templ.guide",
"type": "string",
"enum": ["templ"]
},
{
"description": "https://www.terraform.io/docs/cli/commands/fmt.html",
"type": "string",
Expand Down
18 changes: 13 additions & 5 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ use crate::{
standardrb::format_using_standardrb, stylelint::format_using_stylelint,
stylish_haskell::format_using_stylish_haskell, stylua::format_using_stylua,
swift_format::format_using_swift_format, swiftformat::format_using_swiftformat,
taplo::format_using_taplo, terraform_fmt::format_using_terraform_fmt,
tofu_fmt::format_using_tofu_fmt, typos::format_using_typos, usort::format_using_usort,
xmlformat::format_using_xmlformat, xmllint::format_using_xmllint,
yamlfix::format_using_yamlfix, yamlfmt::format_using_yamlfmt, yapf::format_using_yapf,
yew_fmt::format_using_yew_fmt, zigfmt::format_using_zigfmt, zprint::format_using_zprint,
taplo::format_using_taplo, templ::format_using_templ,
terraform_fmt::format_using_terraform_fmt, tofu_fmt::format_using_tofu_fmt,
typos::format_using_typos, usort::format_using_usort, xmlformat::format_using_xmlformat,
xmllint::format_using_xmllint, yamlfix::format_using_yamlfix,
yamlfmt::format_using_yamlfmt, yapf::format_using_yapf, yew_fmt::format_using_yew_fmt,
zigfmt::format_using_zigfmt, zprint::format_using_zprint,
},
generated::{self, language_to_ext},
terminal::{
Expand Down Expand Up @@ -175,6 +176,7 @@ mod stylua;
mod swift_format;
mod swiftformat;
mod taplo;
mod templ;
mod terraform_fmt;
mod tofu_fmt;
mod typos;
Expand Down Expand Up @@ -730,6 +732,10 @@ pub enum Tooling {
#[serde(rename = "taplo")]
Taplo,

#[doc = "https://templ.guide"]
#[serde(rename = "templ")]
Templ,

#[doc = "https://www.terraform.io/docs/cli/commands/fmt.html"]
#[serde(rename = "terraform_fmt")]
TerraformFmt,
Expand Down Expand Up @@ -893,6 +899,7 @@ impl Tooling {
Self::StylishHaskell => format_using_stylish_haskell(snippet_path),
Self::Stylua => format_using_stylua(snippet_path),
Self::Taplo => format_using_taplo(snippet_path),
Self::Templ => format_using_templ(snippet_path),
Self::TerraformFmt => format_using_terraform_fmt(snippet_path),
Self::TofuFmt => format_using_tofu_fmt(snippet_path),
Self::Typos => format_using_typos(snippet_path),
Expand Down Expand Up @@ -1020,6 +1027,7 @@ impl core::fmt::Display for Tooling {
Self::StylishHaskell => write!(f, "stylish-haskell"),
Self::Stylua => write!(f, "stylua"),
Self::Taplo => write!(f, "taplo"),
Self::Templ => write!(f, "templ"),
Self::TerraformFmt => write!(f, "terraform_fmt"),
Self::TofuFmt => write!(f, "tofu_fmt"),
Self::Typos => write!(f, "typos"),
Expand Down
13 changes: 13 additions & 0 deletions src/formatters/templ.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_templ(
file_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("templ");

cmd.arg("fmt").arg(file_path);

execute_command(&mut cmd, file_path)
}

0 comments on commit b4bade9

Please sign in to comment.