-
Notifications
You must be signed in to change notification settings - Fork 146
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
Adding prettier formatting #660
Conversation
c4933c4
to
c514726
Compare
I'll leave this up for posterity, on the off-chance you're interested. It's water under the bridge to me. I've stripped the unnecessary mypy changes so it merges cleanly from master. Feel free to close |
Doesn't prettier support reading its configuration from |
I feel like I've seen this before, but I can't find any reference to it. Have you come across something; I would also much prefer that (I'm a big fan of single config file). |
No, I haven't actually come across prettier itself before this. |
c514726
to
8ba3ef4
Compare
Ah, no worries. Unfortunately this is the only tool I've found that works consistently for these other file formats, but it comes from the javascript/node world, so it's not particularly designed with python in mind. From my basic searching, I haven't yet found anything that would put the config internal to pyproject.toml; it supports a number of different files but not pyproject: https://prettier.io/docs/en/configuration.html I've always used the TOML file variants when working with python, since the language standardized it's main config format on TOML (at least as far as I'm concerned now that PEP621 is final). Don't merge for now - I'll see if there's a way to accomplish this without too much effort. |
I looked into it more. It's possible to point prettier at pyproject.toml with a "--config" argument, but it spews warnings about unrecognized keys. The config settings would also have to be top level (not in a tool section), so I don't think it's a good solution. It is possible to pass the few configuration parameters as arguments themselves instead of using a config. However, this only works in the context of pre-commit and would be inconsistent with any other tool that also uses prettier. I gave this an attempt and the results were also not stellar - you just end up with different configuration files. So for now, I think these additional config files are the best general solution that seems to work everywhere, including within pre-commit. It has given me an idea to see about fixing this more generically for python, including |
Adding prettier for consistent formatting of non-python files. Ruff format only applies to python files, however, other files in the repo still have similar concerns (consistency, whitespace thrashing, etc). Prettier addresses this concern in the same way as ruff; minimal configurability to prevent bikeshedding. All non-conformant files have been formatted to pass the pre-commit hook. Very few changes were needed; several yaml files were modified to have consistent whitespace and indentation, including the pre-commit configuration file. Modern text editors and IDEs (efficiently) support prettier via plugin; this is recommended for local formatting. A cli tool is available, however, prettier itself is written in javascript so it is only accessible via npm/yarn (`npx prettier`/`yarn dlx prettier`). While this is unfortunate, there are very few tools that format general source files, and none within the python ecosystem. Pre-commit does address this capability gap indirectly. It can be run via `pre-commit run prettier`, either with the `--all-files` flag or by adding a modified file to your working tree. While suboptimal, this does allow local formatting/validation if needed.
8ba3ef4
to
27253a5
Compare
YAML formatting is now handled via |
Lets handle the yaml formatting changes properly 😉
Adding prettier for consistent formatting of non-python files. Ruff format only applies to python files, however, other files in the repo still have similar concerns (consistency, whitespace thrashing, etc). Prettier addresses this concern in the same way as ruff; minimal configurability to prevent bikeshedding.
Prettier is written in javascript but is a generalized tool, handling several other source types (
markdown
,yaml
,json
, etc). While a tool in the python ecosystem would be preferrable, AFAIK no such tool exists. This appears to be whypre-commit
itself directly hosts a prettier integration.