Skip to content

Commit

Permalink
feat: support oxlint
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Jun 15, 2024
1 parent 2232f19 commit 1d45b0e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 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 122 tools.
`mdsf` currently supports 123 tools.

| Formatter | Description |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -185,6 +185,7 @@ mdsf init
| ocamlformat | [https://github.com/ocaml-ppx/ocamlformat](https://github.com/ocaml-ppx/ocamlformat) |
| ocp-indent | [https://github.com/OCamlPro/ocp-indent](https://github.com/OCamlPro/ocp-indent) |
| ormolu | [https://hackage.haskell.org/package/ormolu](https://hackage.haskell.org/package/ormolu) |
| oxlint | [https://oxc.rs](https://oxc.rs) |
| perltidy | [https://github.com/perltidy/perltidy](https://github.com/perltidy/perltidy) |
| pg_format | [https://github.com/darold/pgFormatter](https://github.com/darold/pgFormatter) |
| prettier | [https://github.com/prettier/prettier](https://github.com/prettier/prettier) |
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 @@ -434,6 +434,11 @@
"type": "string",
"enum": ["ormolu"]
},
{
"description": "https://oxc.rs",
"type": "string",
"enum": ["oxlint"]
},
{
"description": "https://github.com/perltidy/perltidy",
"type": "string",
Expand Down
41 changes: 24 additions & 17 deletions src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ use crate::{
nixfmt::format_using_nixfmt, nixpkgs_fmt::format_using_nixpkgs_fmt,
npm_groovy_lint::format_using_npm_groovy_lint, ocamlformat::format_using_ocamlformat,
ocp_indent::format_using_ocp_indent, ormolu::format_using_ormolu,
perltidy::format_using_perltidy, pg_format::format_using_pg_format,
prettier::format_using_prettier, puppet_lint::format_using_puppet_lint,
purs_tidy::format_using_purs_tidy, pyink::format_using_pyink,
rescript_format::format_using_rescript_format, roc_format::format_using_roc_format,
rstfmt::format_using_rstfmt, rubocop::format_using_rubocop, rubyfmt::format_using_rubyfmt,
ruff::format_using_ruff, rufo::format_using_rufo, rustfmt::format_using_rustfmt,
rustywind::format_using_rustywind, scalafmt::format_using_scalafmt,
shfmt::format_using_shfmt, smlfmt::format_using_smlfmt, snakefmt::format_using_snakefmt,
sql_formatter::format_using_sql_formatter, sqlfluff::format_using_sqlfluff,
sqlfmt::format_using_sqlfmt, standardjs::format_using_standardjs,
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, templ::format_using_templ,
terraform_fmt::format_using_terraform_fmt, tofu_fmt::format_using_tofu_fmt,
ts_standard::format_using_ts_standard, typos::format_using_typos,
usort::format_using_usort, xmlformat::format_using_xmlformat,
oxlint::format_using_oxlint, perltidy::format_using_perltidy,
pg_format::format_using_pg_format, prettier::format_using_prettier,
puppet_lint::format_using_puppet_lint, purs_tidy::format_using_purs_tidy,
pyink::format_using_pyink, rescript_format::format_using_rescript_format,
roc_format::format_using_roc_format, rstfmt::format_using_rstfmt,
rubocop::format_using_rubocop, rubyfmt::format_using_rubyfmt, ruff::format_using_ruff,
rufo::format_using_rufo, rustfmt::format_using_rustfmt, rustywind::format_using_rustywind,
scalafmt::format_using_scalafmt, shfmt::format_using_shfmt, smlfmt::format_using_smlfmt,
snakefmt::format_using_snakefmt, sql_formatter::format_using_sql_formatter,
sqlfluff::format_using_sqlfluff, sqlfmt::format_using_sqlfmt,
standardjs::format_using_standardjs, 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,
templ::format_using_templ, terraform_fmt::format_using_terraform_fmt,
tofu_fmt::format_using_tofu_fmt, ts_standard::format_using_ts_standard,
typos::format_using_typos, usort::format_using_usort, xmlformat::format_using_xmlformat,
xmllint::format_using_xmllint, xo::format_using_xo, 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,
Expand Down Expand Up @@ -149,6 +149,7 @@ mod npm_groovy_lint;
mod ocamlformat;
mod ocp_indent;
mod ormolu;
mod oxlint;
mod perltidy;
mod pg_format;
mod prettier;
Expand Down Expand Up @@ -621,6 +622,10 @@ pub enum Tooling {
#[serde(rename = "ormolu")]
Ormolu,

#[doc = "https://oxc.rs"]
#[serde(rename = "oxlint")]
Oxlint,

#[doc = "https://github.com/perltidy/perltidy"]
#[serde(rename = "perltidy")]
PerlTidy,
Expand Down Expand Up @@ -889,6 +894,7 @@ impl Tooling {
Self::OCamlFormat => format_using_ocamlformat(snippet_path),
Self::OcpIndent => format_using_ocp_indent(snippet_path),
Self::Ormolu => format_using_ormolu(snippet_path),
Self::Oxlint => format_using_oxlint(snippet_path),
Self::PerlTidy => format_using_perltidy(snippet_path),
Self::PgFormat => format_using_pg_format(snippet_path),
Self::Prettier => format_using_prettier(snippet_path),
Expand Down Expand Up @@ -1020,6 +1026,7 @@ impl core::fmt::Display for Tooling {
Self::OCamlFormat => write!(f, "ocamlformat"),
Self::OcpIndent => write!(f, "ocpindent"),
Self::Ormolu => write!(f, "ormolu"),
Self::Oxlint => write!(f, "oxlint"),
Self::PerlTidy => write!(f, "perltidy"),
Self::PgFormat => write!(f, "pg_format"),
Self::Prettier => write!(f, "prettier"),
Expand Down
30 changes: 30 additions & 0 deletions src/formatters/oxlint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use super::execute_command;
use crate::{error::MdsfError, runners::setup_npm_script};

#[inline]
fn set_oxlint_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) {
cmd.arg("--fix").arg(snippet_path);
}

#[inline]
fn invoke_oxlint(
mut cmd: std::process::Command,
snippet_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
set_oxlint_args(&mut cmd, snippet_path);

execute_command(&mut cmd, snippet_path)
}

#[inline]
pub fn format_using_oxlint(
snippet_path: &std::path::Path,
) -> Result<(bool, Option<String>), MdsfError> {
if let Ok(path_result) = invoke_oxlint(std::process::Command::new("oxlint"), snippet_path) {
if !path_result.0 {
return Ok(path_result);
}
}

invoke_oxlint(setup_npm_script("oxlint"), snippet_path)
}

0 comments on commit 1d45b0e

Please sign in to comment.