Skip to content

Commit

Permalink
feat(formatters): support brunette (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Oct 11, 2024
1 parent e124430 commit 20097e0
Show file tree
Hide file tree
Showing 5 changed files with 48 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.6...HEAD)

- feat(formatters): support beancount-black [`#488`](https://github.com/hougesen/mdsf/pull/488)
- feat(formatters): support prettytypst [`#487`](https://github.com/hougesen/mdsf/pull/487)
- feat(formatters): support vhdl-style-guide [`#486`](https://github.com/hougesen/mdsf/pull/486)
- feat(formatters): support typstyle [`#485`](https://github.com/hougesen/mdsf/pull/485)
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 186 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 187 tools. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Formatter | Description |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -207,6 +207,7 @@ mdsf init
| blue | [https://blue.readthedocs.io/en/latest/](https://blue.readthedocs.io/en/latest/) |
| bpfmt | [https://source.android.com/docs/setup/reference/androidbp](https://source.android.com/docs/setup/reference/androidbp) |
| brittany | [https://github.com/lspitzner/brittany](https://github.com/lspitzner/brittany) |
| brunette | [https://github.com/odwyersoftware/brunette](https://github.com/odwyersoftware/brunette) |
| bsfmt | [https://github.com/rokucommunity/brighterscript-formatter](https://github.com/rokucommunity/brighterscript-formatter) |
| buf | [https://buf.build/docs/reference/cli/buf/format](https://buf.build/docs/reference/cli/buf/format) |
| buildifier | [https://github.com/bazelbuild/buildtools](https://github.com/bazelbuild/buildtools) |
Expand Down
33 changes: 33 additions & 0 deletions mdsf/src/formatters/brunette.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use super::execute_command;
use crate::{error::MdsfError, runners::CommandType};

#[inline]
pub fn run(snippet_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let mut cmd = CommandType::Direct("brunette").build();

cmd.arg("--quiet").arg(snippet_path);

execute_command(cmd, snippet_path)
}

#[cfg(test)]
mod test_brunette {
use crate::{formatters::setup_snippet, fttype::get_file_extension};

#[test_with::executable(brunette)]
fn it_should_format_python() {
let input = "def add( a: int , b:int)->int: return a+b";

let expected_output = "def add(a: int, b: int) -> int:\n return a + b\n";

let snippet = setup_snippet(input, &get_file_extension("python"))
.expect("it to create a snippet file");

let output = super::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");

assert_eq!(expected_output, output);
}
}
7 changes: 7 additions & 0 deletions mdsf/src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod blade_formatter;
mod blue;
mod bpfmt;
mod brittany;
mod brunette;
mod bsfmt;
mod buf;
mod buildifier;
Expand Down Expand Up @@ -456,6 +457,10 @@ pub enum Tooling {
#[serde(rename = "brittany")]
Brittany,

#[doc = "https://github.com/odwyersoftware/brunette"]
#[serde(rename = "brunette")]
Brunette,

#[doc = "https://www.haskell.org/cabal/"]
#[serde(rename = "cabal_format")]
CabalFormat,
Expand Down Expand Up @@ -1141,6 +1146,7 @@ impl Tooling {
Self::Blue => blue::run(snippet_path),
Self::Bpfmt => bpfmt::run(snippet_path),
Self::Brittany => brittany::run(snippet_path),
Self::Brunette => brunette::run(snippet_path),
Self::Bsfmt => bsfmt::run(snippet_path),
Self::Buf => buf::run(snippet_path),
Self::Buildifier => buildifier::run(snippet_path),
Expand Down Expand Up @@ -1336,6 +1342,7 @@ impl AsRef<str> for Tooling {
Self::Blue => "blue",
Self::Bpfmt => "bpfmt",
Self::Brittany => "brittany",
Self::Brunette => "brunette",
Self::Bsfmt => "bsfmt",
Self::Buf => "buf",
Self::Buildifier => "buildifier",
Expand Down
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 @@ -168,6 +168,11 @@
"type": "string",
"enum": ["brittany"]
},
{
"description": "https://github.com/odwyersoftware/brunette",
"type": "string",
"enum": ["brunette"]
},
{
"description": "https://www.haskell.org/cabal/",
"type": "string",
Expand Down

0 comments on commit 20097e0

Please sign in to comment.