Skip to content

Commit e6a8ef7

Browse files
committed
Add TOML language formatting support to Prettier
Projects may use data files written in the TOML language. A common example of such is the `pyproject.toml` file present in projects that use the Poetry Python package management tool (either for project code dependencies, or development tools). In cases where the TOML content is edited directly by human contributors, it will be useful to provide code formatting infrastructure for TOML files, and to enforce consistent formatting. This is easily accomplished by adding TOML support to the existing code formatting infrastructure via the "prettier-plugin-toml" plugin for the Prettier formatting tool. Poetry's `poetry.lock` file is also written in the TOML language. This file is automatically generated and never manually edited. In this case, the automatically generated content is accepted as-is. So Prettier is configured to exclude the `poetry.lock` file from formatting.
1 parent 5560370 commit e6a8ef7

File tree

10 files changed

+121
-2
lines changed

10 files changed

+121
-2
lines changed

.github/workflows/check-prettier-formatting-task.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ on:
9090
- "**.mkdn?"
9191
- "**.ronn"
9292
- "**.workbook"
93+
# TOML
94+
- "**/Cargo.lock"
95+
- "**/Cargo.toml.orig"
96+
- "**/Gopkg.lock"
97+
- "**/Pipfile"
98+
- "**/pdm.lock"
99+
- "**.toml"
93100
# YAML
94101
- "**/.clang-format"
95102
- "**/.clang-tidy"
@@ -189,6 +196,13 @@ on:
189196
- "**.mkdn?"
190197
- "**.ronn"
191198
- "**.workbook"
199+
# TOML
200+
- "**/Cargo.lock"
201+
- "**/Cargo.toml.orig"
202+
- "**/Gopkg.lock"
203+
- "**/Pipfile"
204+
- "**/pdm.lock"
205+
- "**.toml"
192206
# YAML
193207
- "**/.clang-format"
194208
- "**/.clang-tidy"

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules/
44
/other/clang-format-configuration/testdata/golden/samples/
55
/other/clang-format-configuration/testdata/input/samples/
66
/other/clang-format-configuration/.clang-format
7+
poetry.lock

.prettierrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting/toml/.prettierrc.yml
2+
plugins:
3+
- prettier-plugin-toml

Taskfile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ tasks:
351351
- |
352352
cp \
353353
"{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-javascript/.eslintrc.yml" \
354+
"{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-prettier-formatting/toml/.prettierrc.yml" \
354355
"{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/general/.editorconfig" \
355356
"{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-python/.flake8" \
356357
"{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-markdown/.markdownlint.yml" \

package-lock.json

Lines changed: 62 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"github-label-sync": "3.0.0",
1010
"markdown-link-check": "^3.13.7",
1111
"markdownlint-cli": "^0.45.0",
12-
"prettier": "^3.5.3"
12+
"prettier": "^3.5.3",
13+
"prettier-plugin-toml": "^2.0.5"
1314
},
1415
"dependencies": {
1516
"js-yaml": "^4.1.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.licenses/
22
__pycache__/
33
node_modules/
4+
poetry.lock
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting/toml/.prettierrc.yml
2+
plugins:
3+
- prettier-plugin-toml

workflow-templates/check-prettier-formatting-task.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Use [Prettier](https://prettier.io/docs/en/index.html) to check formatting. Supp
88
- HTML
99
- JSON
1010
- Markdown
11+
- TOML ([via plugin](#toml-support-optional))
1112
- YAML
1213

1314
This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool.
@@ -72,6 +73,25 @@ Add the following to [`/.gitignore`](https://git-scm.com/docs/gitignore):
7273
/node_modules/
7374
```
7475

76+
### TOML Support (Optional)
77+
78+
If the project contains manually maintained [TOML](https://toml.io/) language files, some additional configuration is needed to add support to Prettier for this language.
79+
80+
#### Assets
81+
82+
- [`.prettierrc.yml`](assets/check-prettier-formatting/toml/.prettierrc.yml) - Prettier configuration file
83+
- Install to: repository root.
84+
85+
#### Dependencies
86+
87+
Add the TOML support dependencies by running this command:
88+
89+
```text
90+
npm install --save-dev prettier-plugin-toml@^2.0.2
91+
```
92+
93+
Commit the resulting changes to the `package.json` and `package-lock.json` files.
94+
7595
### Readme badge
7696

7797
Markdown badge:

workflow-templates/check-prettier-formatting-task.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ on:
9090
- "**.mkdn?"
9191
- "**.ronn"
9292
- "**.workbook"
93+
# TOML
94+
- "**/Cargo.lock"
95+
- "**/Cargo.toml.orig"
96+
- "**/Gopkg.lock"
97+
- "**/Pipfile"
98+
- "**/pdm.lock"
99+
- "**.toml"
93100
# YAML
94101
- "**/.clang-format"
95102
- "**/.clang-tidy"
@@ -189,6 +196,13 @@ on:
189196
- "**.mkdn?"
190197
- "**.ronn"
191198
- "**.workbook"
199+
# TOML
200+
- "**/Cargo.lock"
201+
- "**/Cargo.toml.orig"
202+
- "**/Gopkg.lock"
203+
- "**/Pipfile"
204+
- "**/pdm.lock"
205+
- "**.toml"
192206
# YAML
193207
- "**/.clang-format"
194208
- "**/.clang-tidy"

0 commit comments

Comments
 (0)