2024-01-08 08:58:03 +01:00
---
2024-05-18 18:58:57 +02:00
layout: mini
2024-01-08 08:58:03 +01:00
permalink: /n/prettier.html
2024-06-06 15:50:35 +02:00
sitemap: true
robots: noai
2024-05-30 08:05:52 +02:00
lang: en
2024-06-06 15:50:35 +02:00
title: Prettier packages I use
excerpt: I use them both directly, and within pre-commit
2024-01-08 08:58:03 +01:00
---
2024-06-06 15:50:35 +02:00
**{{ page.excerpt }}**
<!-- editorconfig - checker - disable -->
<!-- prettier - ignore - start -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
< em lang = "fi" > Automaattinen sisällysluettelo< / em > / < em lang = "en" > Automatically generated Table of Contents< / em >
- [The packages ](#the-packages )
- [Installation ](#installation )
2024-06-07 05:43:15 +02:00
- [Configuration ](#configuration )
2024-06-06 15:50:35 +02:00
- [`.pre-commit-config.yaml` ](#pre-commit-configyaml )
- [Offline ](#offline )
- [Online ](#online )
- [Further information ](#further-information )
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- prettier - ignore - end -->
<!-- editorconfig - checker - enable -->
## The packages
2024-01-08 08:58:03 +01:00
- [prettier ](https://www.npmjs.com/package/prettier )
- [prettier-plugin-nginx ](https://www.npmjs.com/package/prettier-plugin-nginx )
2024-01-08 11:47:02 +01:00
- [@prettier/plugin-ruby ](https://www.npmjs.com/package/@prettier/plugin-ruby )
2024-01-08 08:58:03 +01:00
- [prettier-plugin-toml ](https://www.npmjs.com/package/prettier-plugin-toml )
2024-01-08 11:47:02 +01:00
- [@prettier/plugin-xml ](https://www.npmjs.com/package/@prettier/plugin-xml )
2024-06-07 05:40:38 +02:00
- [prettier-plugin-sh ](https://www.npmjs.com/package/prettier-plugin-sh )
2024-01-09 07:15:10 +01:00
2024-06-06 15:50:35 +02:00
## Installation
2024-06-07 05:40:38 +02:00
1. `npm install -D -E prettier@3.3.1 prettier-plugin-nginx@1.0.3 @prettier/plugin-ruby@4.0.4 prettier-plugin-toml@2.0.1 @prettier/plugin-xml@3.4.1 prettier-plugin-sh@0.14.0` or probably just `pnpm install -D` if it's not your project.
2024-06-06 15:50:35 +02:00
1. If they don't exist already `echo "{}" > .prettierrc && touch .prettierignore`
1. `pnpm exec prettier . --write` or `pnpm exec prettier . --check`
2024-06-07 05:43:15 +02:00
## Configuration
I do with `.editorconfig` what I can, but for example this site's `.prettierrc` looks like:
```json
{
"plugins": ["@prettier/plugin-xml"],
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }]
}
```
at the time of writing. It's directly from documentation excluding the plugin name, but I will want it everywhere.
2024-06-06 15:50:35 +02:00
## `.pre-commit-config.yaml`
This is the file that controls [`pre-commit`]s behaviour.
### Offline
I accidentally wrote this while updating this page to reflect me using prettier outside of [`pre-commit`] too nowadays. This has the advantage that the same local environment gets reused and dependencies are managed centrally, but assumes everyone uses pnpm, won't work in [`pre-commit` ci] and may have other issues I am not thinking of as a not-coder myself.
[`pre-commit`]: https://pre-commit.com
[`pre-commit` ci]: https://pre-commit.ci
```yaml
ci:
skip: [pnpm-prettier]
repos:
- repo: local
hooks:
- id: pnpm-prettier
name: prettier
2024-06-06 16:35:22 +02:00
entry: pnpm exec prettier --cache --ignore-unknown --write
2024-06-06 15:50:35 +02:00
language: system
# Better handled by pretty-format-json from pre-commit-hooks.
# Remember to have *.json in .prettierignore!
exclude_types: [json]
```
### Online
2024-01-09 07:15:10 +01:00
```yaml
repos:
2024-06-06 15:50:35 +02:00
#- repo: https://github.com/pre-commit/mirrors-prettier
- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.3.1"
2024-01-09 07:15:10 +01:00
hooks:
- id: prettier
2024-06-06 15:50:35 +02:00
# Better handled by pretty-format-json from pre-commit-hooks.
# Remember to have *.json in .prettierignore!
exclude_types: [json]
2024-01-09 07:15:10 +01:00
additional_dependencies: [
# https://aminda.eu/n/prettier
2024-06-06 15:50:35 +02:00
"prettier@3.3.1",
2024-01-09 07:15:10 +01:00
"prettier-plugin-nginx@1.0.3",
"@prettier/plugin-ruby@4.0.4",
"prettier-plugin-toml@2.0.1",
2024-06-06 15:50:35 +02:00
"@prettier/plugin-xml@3.4.1",
2024-01-09 07:15:10 +01:00
]
```
2024-06-06 15:50:35 +02:00
## Further information
- [prettier docs install ](https://prettier.io/docs/en/install )