From f85327c6d76b5268c78fe66b3335ce7bd0e0fb0f Mon Sep 17 00:00:00 2001 From: Mads Hougesen Date: Sun, 27 Oct 2024 00:37:29 +0200 Subject: [PATCH] feat: support purty (#515) --- CHANGELOG.md | 1 + README.md | 3 ++- mdsf/src/tools/mod.rs | 7 ++++++ mdsf/src/tools/purty.rs | 39 +++++++++++++++++++++++++++++++++ schemas/v0.2.7/mdsf.schema.json | 5 +++++ tools/purty/plugin.json | 15 +++++++++++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 mdsf/src/tools/purty.rs create mode 100644 tools/purty/plugin.json diff --git a/CHANGELOG.md b/CHANGELOG.md index fbad5a6..d8ac7c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.2.7...HEAD) +- feat: support purty [`#515`](https://github.com/hougesen/mdsf/pull/515) - feat: support nginxbeautifier [`#514`](https://github.com/hougesen/mdsf/pull/514) - feat: support cabal-fmt [`#513`](https://github.com/hougesen/mdsf/pull/513) - feat: support bibtex-tidy [`#512`](https://github.com/hougesen/mdsf/pull/512) diff --git a/README.md b/README.md index 0679808..98072ed 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ mdsf init -`mdsf` currently supports 205 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 +`mdsf` currently supports 206 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃 | Name | Command | | ------------------------ | -------------------------------------------------------------------------------------- | @@ -326,6 +326,7 @@ mdsf init | `protolint` | `protolint lint -fix PATH` | | `puppet-lint` | `puppet-lint --fix PATH` | | `purs-tidy` | `purs-tidy format-in-place PATH` | +| `purty` | `purty --write PATH` | | `pycln` | `pycln --no-gitignore --quiet PATH` | | `pyink` | `pyink --quiet PATH` | | `qmlfmt` | `qmlfmt -w PATH` | diff --git a/mdsf/src/tools/mod.rs b/mdsf/src/tools/mod.rs index a47858f..5ef8142 100644 --- a/mdsf/src/tools/mod.rs +++ b/mdsf/src/tools/mod.rs @@ -136,6 +136,7 @@ pub mod prettypst; pub mod protolint; pub mod puppet_lint; pub mod purs_tidy; +pub mod purty; pub mod pycln; pub mod pyink; pub mod qmlfmt; @@ -760,6 +761,10 @@ pub enum Tooling { /// `purs-tidy format-in-place $PATH` PursTidy, + #[serde(rename = "purty")] + /// `purty --write $PATH` + Purty, + #[serde(rename = "pycln")] /// `pycln --no-gitignore --quiet $PATH` Pycln, @@ -1175,6 +1180,7 @@ impl Tooling { Self::Protolint => protolint::run(snippet_path), Self::PuppetLint => puppet_lint::run(snippet_path), Self::PursTidy => purs_tidy::run(snippet_path), + Self::Purty => purty::run(snippet_path), Self::Pycln => pycln::run(snippet_path), Self::Pyink => pyink::run(snippet_path), Self::Qmlfmt => qmlfmt::run(snippet_path), @@ -1389,6 +1395,7 @@ impl AsRef for Tooling { Self::Protolint => "protolint", Self::PuppetLint => "puppet_lint", Self::PursTidy => "purs_tidy", + Self::Purty => "purty", Self::Pycln => "pycln", Self::Pyink => "pyink", Self::Qmlfmt => "qmlfmt", diff --git a/mdsf/src/tools/purty.rs b/mdsf/src/tools/purty.rs new file mode 100644 index 0000000..54c5174 --- /dev/null +++ b/mdsf/src/tools/purty.rs @@ -0,0 +1,39 @@ +use std::process::Command; + +use crate::{error::MdsfError, execution::execute_command, runners::CommandType}; + +#[inline] +fn set_purty_args(mut cmd: Command, file_path: &std::path::Path) -> Command { + cmd.arg("--write"); + cmd.arg(file_path); + cmd +} + +#[inline] +pub fn run(file_path: &std::path::Path) -> Result<(bool, Option), MdsfError> { + let commands = [ + CommandType::NodeModules("purty"), + CommandType::Direct("purty"), + CommandType::Npm("purty"), + ]; + + for (index, cmd) in commands.iter().enumerate() { + let cmd = set_purty_args(cmd.build(), file_path); + let execution_result = execute_command(cmd, file_path); + + if index == commands.len() - 1 { + return execution_result; + } + + if let Ok(r) = execution_result { + if !r.0 { + return Ok(r); + } + } + } + + Ok((true, None)) +} + +#[cfg(test)] +mod test_purty {} diff --git a/schemas/v0.2.7/mdsf.schema.json b/schemas/v0.2.7/mdsf.schema.json index 31d8fc1..1cef7ea 100644 --- a/schemas/v0.2.7/mdsf.schema.json +++ b/schemas/v0.2.7/mdsf.schema.json @@ -748,6 +748,11 @@ "type": "string", "enum": ["purs-tidy"] }, + { + "description": "`purty --write $PATH`", + "type": "string", + "enum": ["purty"] + }, { "description": "`pycln --no-gitignore --quiet $PATH`", "type": "string", diff --git a/tools/purty/plugin.json b/tools/purty/plugin.json new file mode 100644 index 0000000..35614b7 --- /dev/null +++ b/tools/purty/plugin.json @@ -0,0 +1,15 @@ +{ + "$schema": "../tool.schema.json", + "binary": "purty", + "categories": ["formatter"], + "commands": { + "": ["--write", "$PATH"] + }, + "description": "PureScript pretty-printer", + "homepage": "https://gitlab.com/joneshf/purty", + "languages": ["purescript"], + "name": null, + "npm": "purty", + "php": null, + "tests": [] +}