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(markdown): support typos #228

Merged
merged 1 commit into from
May 29, 2024
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mdsf init
| Kcl | `kcl_fmt` |
| Kotlin | `ktfmt`, `ktlint` |
| Lua | `luaformatter`, `stylua` |
| Markdown | `mdformat`, `prettier` |
| Markdown | `mdformat`, `prettier`, `typos` |
| Mustache | `djlint` |
| Nim | `nimpretty` |
| Nix | `alejandra`, `nixfmt`, `nixpkgs-fmt` |
Expand Down
2 changes: 1 addition & 1 deletion schemas/v0.0.6/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@
},
"Markdown": {
"type": "string",
"enum": ["prettier", "mdformat"]
"enum": ["prettier", "mdformat", "typos"]
},
"MdsfFormatter_for_Blade": {
"anyOf": [
Expand Down
1 change: 1 addition & 0 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub mod swiftformat;
pub mod taplo;
pub mod terraform_fmt;
pub mod tofu_fmt;
pub mod typos;
pub mod usort;
pub mod xmlformat;
pub mod xmllint;
Expand Down
13 changes: 13 additions & 0 deletions src/formatters/typos.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_typos(
snippet_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = std::process::Command::new("typos");

cmd.arg(snippet_path);

execute_command(&mut cmd, snippet_path)
}
9 changes: 8 additions & 1 deletion src/languages/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use schemars::JsonSchema;
use super::{Lang, LanguageFormatter};
use crate::{
error::MdsfError,
formatters::{mdformat::format_using_mdformat, prettier::format_using_prettier, MdsfFormatter},
formatters::{
mdformat::format_using_mdformat, prettier::format_using_prettier,
typos::format_using_typos, MdsfFormatter,
},
};

#[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)]
Expand All @@ -14,6 +17,8 @@ pub enum Markdown {
Prettier,
#[serde(rename = "mdformat")]
MdFormat,
#[serde(rename = "typos")]
Typos,
}

impl core::fmt::Display for Markdown {
Expand All @@ -22,6 +27,7 @@ impl core::fmt::Display for Markdown {
match self {
Self::Prettier => write!(f, "prettier"),
Self::MdFormat => write!(f, "mdformat"),
Self::Typos => write!(f, "typos"),
}
}
}
Expand Down Expand Up @@ -55,6 +61,7 @@ impl LanguageFormatter for Markdown {
match self {
Self::Prettier => format_using_prettier(snippet_path),
Self::MdFormat => format_using_mdformat(snippet_path),
Self::Typos => format_using_typos(snippet_path),
}
}
}
Expand Down
Loading