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(formatter): supprt refmt #378

Merged
merged 1 commit into from
Jun 28, 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/target
/codegen/target
/target
node_modules
package-lock.json
package.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mdsf init

<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 172 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 173 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Formatter | Description |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -322,6 +322,7 @@ mdsf init
| pyink | [https://github.com/google/pyink](https://github.com/google/pyink) |
| qmlfmt | [https://github.com/jesperhh/qmlfmt](https://github.com/jesperhh/qmlfmt) |
| raco_fmt | [https://docs.racket-lang.org/fmt/](https://docs.racket-lang.org/fmt/) |
| refmt | [https://reasonml.github.io/docs/en/](https://reasonml.github.io/docs/en/) |
| rescript_format | [https://rescript-lang.org/](https://rescript-lang.org/) |
| roc_format | [https://github.com/roc-lang/roc](https://github.com/roc-lang/roc) |
| rstfmt | [https://github.com/dzhu/rstfmt](https://github.com/dzhu/rstfmt) |
Expand Down
5 changes: 5 additions & 0 deletions schemas/v0.2.1/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,11 @@
"type": "string",
"enum": ["rescript_format"]
},
{
"description": "https://reasonml.github.io/docs/en/",
"type": "string",
"enum": ["refmt"]
},
{
"description": "https://github.com/roc-lang/roc",
"type": "string",
Expand Down
7 changes: 7 additions & 0 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ mod pycln;
mod pyink;
mod qmlfmt;
mod raco;
mod refmt;
mod rescript_format;
mod roc_format;
mod rstfmt;
Expand Down Expand Up @@ -837,6 +838,10 @@ pub enum Tooling {
#[serde(rename = "rescript_format")]
ReScriptFormat,

#[doc = "https://reasonml.github.io/docs/en/"]
#[serde(rename = "refmt")]
Refmt,

#[doc = "https://github.com/roc-lang/roc"]
#[serde(rename = "roc_format")]
RocFormat,
Expand Down Expand Up @@ -1161,6 +1166,7 @@ impl Tooling {
Self::Qmlfmt => qmlfmt::run(snippet_path),
Self::RacoFmt => raco::run_fmt(snippet_path),
Self::ReScriptFormat => rescript_format::run(snippet_path),
Self::Refmt => refmt::run(snippet_path),
Self::RocFormat => roc_format::run(snippet_path),
Self::RstFmt => rstfmt::run(snippet_path),
Self::RuboCop => rubocop::run(snippet_path),
Expand Down Expand Up @@ -1332,6 +1338,7 @@ impl AsRef<str> for Tooling {
Self::Qmlfmt => "qmlfmt",
Self::RacoFmt => "raco_fmt",
Self::ReScriptFormat => "rescript_format",
Self::Refmt => "refmt",
Self::RocFormat => "roc_format",
Self::RstFmt => "rstfmt",
Self::RuboCop => "rubocop",
Expand Down
25 changes: 25 additions & 0 deletions src/formatters/refmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use super::execute_command;
use crate::{error::MdsfError, runners::CommandType};

#[inline]
fn set_refmt_args(
mut cmd: std::process::Command,
snippet_path: &std::path::Path,
) -> std::process::Command {
cmd.arg("--in-place").arg(snippet_path);

cmd
}

#[inline]
fn invoke_refmt(
cmd: std::process::Command,
snippet_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
execute_command(set_refmt_args(cmd, snippet_path), snippet_path)
}

#[inline]
pub fn run(snippet_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
invoke_refmt(CommandType::Direct("refmt").build(), snippet_path)
}
Loading