Skip to content

Commit

Permalink
feat: support purty (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Oct 26, 2024
1 parent 367021a commit f85327c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mdsf init
<!-- START_SECTION:supported-tools -->

`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 |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -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` |
Expand Down
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1389,6 +1395,7 @@ impl AsRef<str> 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",
Expand Down
39 changes: 39 additions & 0 deletions mdsf/src/tools/purty.rs
Original file line number Diff line number Diff line change
@@ -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<String>), 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 {}
5 changes: 5 additions & 0 deletions schemas/v0.2.7/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions tools/purty/plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit f85327c

Please sign in to comment.