Add a project .editorconfig file#7081
Conversation
This adds settings based on some common-sense values and the Cirq project's current conventions, such as line length and use of spaces instead of tabs.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7081 +/- ##
==========================================
- Coverage 98.17% 98.17% -0.01%
==========================================
Files 1089 1089
Lines 95217 95217
==========================================
- Hits 93481 93475 -6
- Misses 1736 1742 +6 ☔ View full report in Codecov by Sentry. |
| # Important setting: trailing whitspace is meaningful in Markdown. | ||
| trim_trailing_whitespace = false |
There was a problem hiding this comment.
Can you please comment when is this needed?
My impression was that trailing spaces in md were basically a noise that would be better removed.
There was a problem hiding this comment.
It's a little bit bonkers, but the use of 2 trailing spaces is one of the ways that md lets you indicate an explicit line breeak. Here are a couple of places where this is described:
- https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#line-breaks
- https://www.markdownguide.org/basic-syntax/#:~:text=Line%20Breaks,spaces%2C%20and%20then%20type%20return.
I'll try to find a public spec somewhere and add a comment to the .editorconfig file to point to it.
The Google md style recommentation (which I can't find atm) recommends avoiding this construct. However, because it's technically allowed, and because other style guides and formatters pay attention to it, and because there doesn't seem to be a setting in editorconfig for "allow exactly 2 spaces but remove 1 or 3+ spaces", the only safe thing to do for md files seems to be to disable the setting to remove trailing whitespace. (If there's a better way, I'm completely happy to do it!)
There was a problem hiding this comment.
Actually, I didn't test this, but I bet 3 or more spaces would also produce a line break.
There was a problem hiding this comment.
Ah, markdownlint has a setting to control this: https://github.com/markdownlint/markdownlint/blob/main/docs/RULES.md#md009---trailing-spaces
The default is 2 spaces, meaning it will flag single spaces at the ends of lines.
There was a problem hiding this comment.
There are only 3 places in our markdown files that have 2 trailing blanks. None of those is necessary; they don't really seem intentional.
$ git grep -n "\s{2,}$" "*.md" "*.mark*"
.github/ISSUE_TEMPLATE/project_health.md:3:about: Issues related to CI, automation infra, clean code, depreca>
docs/dev/nomenclature.md:14:`wave_function`, or `state` for this object (`state` is too overloaded).
docs/dev/style.md:13:with the following guidance.I think the Google style guide recommendation against trailing double-spaces is reasonable.
They make text behave differently without visible markup, which makes it harder to judge if those spaces are intentional or left over from text editing. It is IMO better to stick to the explicit \ or <br> syntax for creating manual linebreaks.
Can we disallow trailing blanks in editorconfig and also flag them as errors in markdownlint?
There was a problem hiding this comment.
Yes; I'll make the change and push an update. (Actually, I just looked at our .markdownlintrc again, and it turns out it already disallows trailing spaces.)
Per discussion in the [review comments](quantumlib#7081 (comment)), the feeling is that it's better to avoid trailing spaces because they are bad for several reasons.
* Resolve quantumlib#6998: add a .editorconfig file This adds settings based on some common-sense values and the Cirq project's current conventions, such as line length and use of spaces instead of tabs. * Add explanation for .md setting for trailing spaces * Take out exception to trailing spaces rule for .md files Per discussion in the [review comments](quantumlib#7081 (comment)), the feeling is that it's better to avoid trailing spaces because they are bad for several reasons.
This adds settings based on some common-sense values and the Cirq project's current conventions, such as line length and use of spaces instead of tabs.
This resolves #6998.