n/prettier.md: update and explain my opinions

This commit is contained in:
Aminda Suomalainen 2024-07-07 10:08:39 +03:00
parent 12c7abf641
commit dda75342c9
Signed by: Mikaela
SSH Key Fingerprint: SHA256:CXLULpqNBdUKB6E6fLA1b/4SzG0HvKD19PbIePU175Q
1 changed files with 53 additions and 19 deletions

View File

@ -22,7 +22,6 @@ _{{ page.excerpt }}_
- [Configuration](#configuration) - [Configuration](#configuration)
- [`.pre-commit-config.yaml`](#pre-commit-configyaml) - [`.pre-commit-config.yaml`](#pre-commit-configyaml)
- [Offline](#offline) - [Offline](#offline)
- [Online](#online)
- [Further information](#further-information) - [Further information](#further-information)
<!-- END doctoc generated TOC please keep comment here to allow auto update --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->
@ -50,14 +49,35 @@ _{{ page.excerpt }}_
## Configuration ## Configuration
I do with `.editorconfig` what I can, but for example my template `.prettierrc` I do with `.editorconfig` what I can, but for example my template
looks like: `.prettierrc.json` looks like this. I use pre-commit's pretty-format-json, while
the one included on this page gets managed by prettier.
```json ```json
{ {
"bracketSameLine": true,
"endOfLine": "auto",
"insertPragma": true, "insertPragma": true,
"proseWrap": "always", "overrides": [
"singleAttributePerLine": true, {
"files": ".prettierrc",
"options": {
"parser": "json"
}
},
{
"files": "conf/librewolf.overrides.cfg",
"options": {
"parser": "babel"
}
},
{
"files": "conf/autoconfig.js.online",
"options": {
"parser": "babel"
}
}
],
"plugins": [ "plugins": [
"@prettier/plugin-ruby", "@prettier/plugin-ruby",
"@prettier/plugin-xml", "@prettier/plugin-xml",
@ -65,22 +85,32 @@ looks like:
"prettier-plugin-sh", "prettier-plugin-sh",
"prettier-plugin-toml" "prettier-plugin-toml"
], ],
"overrides": [ "proseWrap": "always",
{ "files": ".prettierrc", "options": { "parser": "json" } }, "quoteProps": "consistent",
{ "requirePragma": false,
"files": "conf/librewolf.overrides.cfg", "singleAttributePerLine": true
"options": { "parser": "babel" }
},
{
"files": "conf/autoconfig.js.online",
"options": { "parser": "babel" }
}
]
} }
``` ```
at the time of writing. It's directly from documentation excluding the plugin See the documentation linked on the bottom, but here are some explanations
names, but I will want it everywhere. anyway:
- `bracketSameLine: true` - HTML tags closing on the same line as something else
just looks so much better for my eyes.
- `endOfLine: auto` - The default is `lf` line-endings, which I support in
general, but I think `prettier` is the wrong place to configure it. I have it
in `.gitattributes` which will take priority on check-in and `.editorconfig`.
- `insertPragma: true` - adds a comment on files formatted
- `overrides` and `plugins` - self-explanatory, but if not see the documentation
(bottom of the page). I know I don't actually have `.prettierrc` as it's
`.prettierrc.json`, but it doesn't seem to hurt and `babel` seems to be used
for JavaScript by default, which those two are regardless of the name.
- `proseWrap: always` - wraps long markdown lines as individual newlines don't
matter (two begin a new paragraph).
- `quoteProps: consistent` - quotes things if anything is quoted.
- `requirePragma: false` - the other side of `insertPragma: true`, it's here as
a note to self.
- `singleAttributePerLine: true` - I just think it looks better.
## `.pre-commit-config.yaml` ## `.pre-commit-config.yaml`
@ -117,9 +147,11 @@ repos:
language: system language: system
# Better handled by pretty-format-json from pre-commit-hooks. # Better handled by pretty-format-json from pre-commit-hooks.
# Remember to have *.json in .prettierignore! # Remember to have *.json in .prettierignore!
exclude_types: [json] #exclude_types: [json]
``` ```
<!--
### Online ### Online
```yaml ```yaml
@ -142,6 +174,8 @@ repos:
] ]
``` ```
-->
## Further information ## Further information
- [prettier docs install](https://prettier.io/docs/en/install) - [prettier docs install](https://prettier.io/docs/en/install)