Skip to content

Commit

Permalink
feat: add support for fallback formatters (#69)
Browse files Browse the repository at this point in the history
* feat: implement support for multiple formatters

* feat: implement multiple formatters for python

* feat: add support for fallback formatters for all languages

* refactor: remove a lot of dupplicate code

* chore: update schema

* style: format code

* chore: add formatting to precommit command

* fix: remove default_enabled

* feat: setup default fallback formatters

* chore: rename format_single to format_snippet

* test: validate fallback formatters work

* docs: document formatter configuration
  • Loading branch information
hougesen authored Mar 16, 2024
1 parent 1c45e59 commit 2c8c8e5
Show file tree
Hide file tree
Showing 37 changed files with 1,814 additions and 1,409 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test-coverage:

precommit:
cargo clean
cargo fmt
make build
make lint
make test
Expand Down
72 changes: 43 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,53 @@ If you are interested in customizing which formatter is run, you can create a ne
mdsf init
```

`mdsf` supports running multiple formatters on the save code snippet.

```json
{
// Only run `ruff` on Python snippets,
"python": "ruff",
// Run `usort` on file and then `black`
"python": ["usort", "black"],
// Run `usort`, if that fails run `isort`, finally run `black`
"python": [["usort", "isort"], "black"]
}
```

### Supported languages & formatters

> \[!NOTE\]
> mdsf is not a tool for installing formatters.
>
> Only formatters that are already installed will be used.
| Language | Formatters |
| ----------- | ----------------------------------------------- |
| C | `clang-format` |
| CSS | `prettier` |
| Cpp | `clang-format` |
| Crystal | `crystal_format` |
| Dart | `dart_format` |
| Elixir | `mix_format` |
| Gleam | `gleam_format` |
| Go | `gofmt`, `gofumpt` |
| HTML | `prettier` |
| JSON | `prettier`, `biome`, `clang-format`, `deno_fmt` |
| Java | `clang-format` |
| JavaScript | `prettier`, `biome`, `clang-format`, `deno_fmt` |
| Lua | `stylua` |
| Nim | `nimpretty` |
| Objective C | `clang-format` |
| Protobuf | `clang-format` |
| Python | `ruff`, `black`, `blue`, `yapf`, `autopep8` |
| Roc | `roc_format` |
| Ruby | `rubocop` |
| Rust | `rustfmt` |
| SQL | `sqlfluff`, `sql-formatter` |
| Shell | `shfmt` |
| TOML | `taplo` |
| TypeScript | `prettier`, `biome`, `deno_fmt` |
| Vue | `prettier` |
| YAML | `prettier` |
| Zig | `zigfmt` |
| Language | Formatters |
| ----------- | ------------------------------------------------------------- |
| C | `clang-format` |
| Cpp | `clang-format` |
| Crystal | `crystal_format` |
| CSharp | `clang-format` |
| CSS | `prettier` |
| Dart | `dart_format` |
| Elixir | `mix_format` |
| Gleam | `gleam_format` |
| Go | `gofmt`, `gofumpt` |
| HTML | `prettier` |
| Java | `clang-format` |
| JavaScript | `prettier`, `biome`, `clang-format`, `deno_fmt` |
| JSON | `prettier`, `biome`, `clang-format`, `deno_fmt` |
| Lua | `stylua` |
| Nim | `nimpretty` |
| Objective C | `clang-format` |
| Protobuf | `clang-format` |
| Python | `ruff`, `black`, `blue`, `yapf`, `autopep8`, `isort`, `usort` |
| Roc | `roc_format` |
| Ruby | `rubocop` |
| Rust | `rustfmt` |
| Shell | `shfmt` |
| SQL | `sqlfluff`, `sql-formatter` |
| TOML | `taplo` |
| TypeScript | `prettier`, `biome`, `deno_fmt` |
| Vue | `prettier` |
| YAML | `prettier` |
| Zig | `zigfmt` |
7 changes: 7 additions & 0 deletions mdsf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/hougesen/mdsf/main/schemas/v0.0.1/mdsf.schema.json",
"markdown": {
"enabled": false,
"formatter": []
}
}
Loading

0 comments on commit 2c8c8e5

Please sign in to comment.