Skip to content

Add a project .editorconfig file #7081

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

Merged
merged 4 commits into from
Feb 25, 2025
Merged

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Feb 23, 2025

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.

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.
@CirqBot CirqBot added the size: S 10< lines changed <50 label Feb 23, 2025
@mhucka mhucka marked this pull request as ready for review February 23, 2025 06:08
@mhucka mhucka requested review from vtomole and a team as code owners February 23, 2025 06:08
@mhucka mhucka requested a review from maffoo February 23, 2025 06:08
@mhucka mhucka enabled auto-merge February 23, 2025 06:08
@mhucka mhucka self-assigned this Feb 23, 2025
@mhucka mhucka added the kind/health For CI/testing/release process/refactoring/technical debt items label Feb 23, 2025
Copy link

codecov bot commented Feb 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.17%. Comparing base (931bc66) to head (2531c2f).
Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@mhucka mhucka changed the title Resolve #6998: add a .editorconfig file Add a .editorconfig file Feb 23, 2025
.editorconfig Outdated
Comment on lines 17 to 18
# Important setting: trailing whitspace is meaningful in Markdown.
trim_trailing_whitespace = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

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!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I didn't test this, but I bet 3 or more spaces would also produce a line break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

@pavoljuhas pavoljuhas Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

mhucka and others added 3 commits February 24, 2025 07:37
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.
@mhucka mhucka mentioned this pull request Feb 25, 2025
Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mhucka mhucka added this pull request to the merge queue Feb 25, 2025
Merged via the queue into quantumlib:main with commit 96583fe Feb 25, 2025
38 checks passed
@mhucka mhucka deleted the mh-add-editorconfig branch February 25, 2025 19:53
@mhucka mhucka changed the title Add a .editorconfig file Add a project .editorconfig file Apr 8, 2025
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/health For CI/testing/release process/refactoring/technical debt items size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a .editorconfig file
3 participants