-
-
Notifications
You must be signed in to change notification settings - Fork 306
Description
My understanding from submitting PRs like #2159 is that the project wants code to be formatted without trailing commas.
As a principle, I am happy to defer on any formatter preferences, but I thought it might be helpful to get clarity on two issues which affect contribution:
- I could not find this in the docs/CONTRIBUTING.md
- I don't believe that there are any autoformatters which can apply this custom behavior / check for violations automatically. (If I am incorrect, please let me know since that would resolve this issue)
- This adds extra work for contributors to manually add and maintainers to manually check
- flake8/ruff have custom hooks to check for the presence of trailing commas but not any to ensure there are none.
- autopep8, black & ruff all generally are agnostic on this or suggest to add trailing commas for the purpose of cleaner git diffs when editing lists
Context
Before I contribute I try to run an autoformatter like ruff to ensure the maintainers don't need to check for style issues.
I can automatically set the prefered line length and quote style for the project without issue. However, there is no way to set the trailing comma preference.
i.e. something like this
uvx ruff format --line-length 80 pygeoapi/api/__init__.py --config "format.quote-style = 'single'" && uvx flake8
This is a bit of a headache in large PRs since it requires manually editing code from an autoformatter each time, effectively preventing its use until the final PR.
My understanding is that PEP 8 says trailing commas are optional or encouraged
When trailing commas are redundant, they are often helpful when a version control system is used, when a list of values, arguments or imported items is expected to be extended over time. The pattern is to put each value (etc.) on a line by itself, always adding a trailing comma, and add the close parenthesis/bracket/brace on the next line.
