docs: add list of known formatters

This commit is contained in:
zimbatm 2021-02-26 22:02:11 +01:00
parent f6880f1fa2
commit 6b72db4087
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
4 changed files with 144 additions and 34 deletions

View File

@ -1,6 +1,102 @@
# A list of known formatters
| name | files as argument | write-in-place | update-mtime |
| --------- | ----------------- | -------------- | -------------------- |
| gofmt | yes | yes | keeps the same mtime |
| cargo fmt | no | yes | yes |
Here is a list of all the formatters we tested. Feel free to send a PR to add
other ones!
## [prettier](https://prettier.io/)
An opinionated code formatter that supports many languages.
```toml
command = "prettier"
options = ["--write"]
includes = [
"*.css",
"*.html",
"*.js",
"*.json",
"*.jsx",
"*.md",
"*.mdx",
"*.scss",
"*.ts",
"*.yaml",
]
```
## [Black](https://github.com/psf/black)
A python formatter.
```toml
command = "black"
includes = ["*.py"]
```
## Elm
```toml
command = "elm-format"
options = ["--yes"]
includes = ["*.elm"]
```
## Go
```toml
command = "gofmt"
options = ["-w"]
includes = ["*.go"]
```
## [Ormolu](https://github.com/tweag/ormolu)
Haskell formatter
```toml
command = "ormolu"
options = [
"--ghc-opt", "-XBangPatterns",
"--ghc-opt", "-XPatternSynonyms",
"--ghc-opt", "-XTypeApplications",
"--mode", "inplace",
"--check-idempotence",
]
includes = ["*.hs"]
```
## [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)
Nix code formatter.
```toml
command = "nixpkgs-fmt"
includes = ["*.nix"]
```
## rustfmt
```toml
command = "rustfmt"
options = ["--edition", "2018"]
includes = ["*.rs"]
```
## cargo fmt
`cargo fmt` is not supported as it doesn't follow the spec.
## [shfmt](https://github.com/mvdan/sh)
A shell code formatter.
```toml
command = "shfmt"
options = [
"-i",
"2", # indent 2
"-s", # simplify the code
"-w", # write back to the file
]
includes = ["*.sh"]
```

View File

@ -1,24 +1,22 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
"type": "application",
"source-directories": ["src"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"test-dependencies": {
"direct": {},
"indirect": {}
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}

10
examples/html/index.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Title</title>
</head>
<body>
<h1>Hi!</h1>
</body>
</html>

View File

@ -26,20 +26,26 @@ options = [
includes = ["*.hs"]
excludes = ["examples/haskell/"]
[formatter.javascript]
command = "prettier"
options = ["--write"]
includes = ["*.js"]
[formatter.markdown]
command = "prettier"
options = ["--write"]
includes = ["*.md"]
[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]
[formatter.prettier]
command = "prettier"
options = ["--write"]
includes = [
"*.css",
"*.html",
"*.js",
"*.json",
"*.jsx",
"*.md",
"*.mdx",
"*.scss",
"*.ts",
"*.yaml",
]
[formatter.rust]
command = "rustfmt"
options = ["--edition", "2018"]