-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add taplo
pre-commit hook to format and sort toml
files
#6781
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6781 +/- ##
=======================================
Coverage 97.49% 97.49%
=======================================
Files 143 143
Lines 28177 28177
=======================================
Hits 27472 27472
Misses 705 705 |
pyproject.toml
Outdated
in_place = true | ||
# Sorting options: | ||
no_sort_tables = true | ||
sort_inline_arrays = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's desirable to have separate PRs, one for formatting and another for sorting, we can remove sort_inline_arrays = true
and add this line in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+100 sorting TOML files. However, could you consider whether using Taplo might be a better option compared to toml-sort?
I have no preference, |
hooks: | ||
- id: taplo-format | ||
# See options: https://taplo.tamasfe.dev/configuration/formatter-options.html | ||
args: [--option, "reorder_arrays=true"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With fb0df95 I opted not to use indent_string
, so the default indent of 2 spaces is used. This is also the default for toml-sort
. I think it's okay to use the default 2 spaces, but we can use 4 if preferred
args: [--option, "reorder_arrays=true"] | |
args: [--option, "reorder_arrays=true", --option, "indent_string= "] |
Have a look at the other options, are there any else we should include (can also add options in a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff is better with "indent_string= "
enabled if that's desired (i.e. fewer formatting changes). It's easier to see the sorting that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 using default.
toml-sort
pre-commit hook and use it to format pyproject.toml
taplo
pre-commit hook to format and sort toml
files
Co-authored-by: user27182 <[email protected]>
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
pyproject.toml
Outdated
'cmocean<4.0.4', | ||
'colorcet<3.2.0', | ||
'pyvista[pinned]', | ||
# Embreex does not work with arm-based macs | ||
'embreex<2.17.8; sys_platform != "darwin" or platform_machine != "arm64"', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bug with the sorting? We have p
before e
, not a huge deal but not expected either.
Edit: looks like the comment between items may have thrown it off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following #6782, let's move comment inline. Additionally, it may be helpful to consider submitting an issue to Taplo regarding why the sorting functionality is not working as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following #6782, let's move comment inline.
Fixed in d0eb514
Additionally, it may be helpful to consider submitting an issue to Taplo regarding why the sorting functionality is not working as expected.
Apparently having full-line comments split up the sorting is the expected behaviour, see tamasfe/taplo#675
So we should generally avoid using any full-line comments in any toml
files with this tool.
pyproject.toml
Outdated
'cmocean<4.0.4', | ||
'colorcet<3.2.0', | ||
'pyvista[pinned]', | ||
# Embreex does not work with arm-based macs | ||
'embreex<2.17.8; sys_platform != "darwin" or platform_machine != "arm64"', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following #6782, let's move comment inline. Additionally, it may be helpful to consider submitting an issue to Taplo regarding why the sorting functionality is not working as expected.
Overview
toml
files are not currently formatted or sorted. This enables things like:pyvista/pyproject.toml
Lines 69 to 74 in a71e027
Where spaces around
=
are not enforced and where alphabetical sorting is not enforced (we haven
->m
->n
order in the example)This PR uses
https://github.com/pappasam/toml-sorthttps://github.com/tamasfe/taplo to fix and enforce the formatting and sorting.