Skip to content
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 task-tags & ignore-overlong-task-comments settings #1550

Merged
merged 4 commits into from Jan 4, 2023

Conversation

not-my-profile
Copy link
Contributor

@not-my-profile not-my-profile commented Jan 2, 2023

Programmers often leave comments to themselves and others such as:

# TODO: Use a faster algorithm?

The keywords used to prefix such comments are just a convention and vary from project to project. Other common keywords include FIXME and HACK.

The keywords in use for the codebase are of interest to ruff because ruff does also lint comments. For example the ERA lint detects commented-out code but ignores comments starting with such a keyword. Previously the ERA lint simply hardcoded the regular expression TODO|FIXME|XXX to achieve that. This commit introduces a new task-tags setting to make this configurable (and to allow other comment lints to recognize the same set of keywords).

The term "task tags" has probably been popularized by the Eclipse IDE. For Python there has been the proposal PEP 350, which referred to such keywords as "codetags". That proposal however has been rejected. We are choosing the term "task tags" over "code tags" because the former is more descriptive: a task tag describes a task.

While according to the PEP 350 such keywords are also sometimes used for non-tasks e.g. NOBUG to describe a well-known problem that will never be addressed due to design problems or domain limitations, such keywords are so rare that we are neglecting them here in favor of more descriptive terminology. The vast majority of such keywords does describe tasks, so naming the setting "task-tags" is apt.

@charliermarsh
Copy link
Member

I don't think we should avoid flagging long-line violations for TODOs by default. If we want to support this for E501, it should be opt-in, in my opinion.

@not-my-profile
Copy link
Contributor Author

Fair enough ... do you have an idea what the flag should be called? How about:

[tool.ruff.pycodestyle]
allow-overlong-lines-for-comment-tags = true

@charliermarsh
Copy link
Member

That looks reasonable. Or ignore-long-comment-tags as something more succinct? But what you have is more specific.

@not-my-profile
Copy link
Contributor Author

I think long-comment-tags would be confusing since it's not the comment tags that are long but the text that follows them.

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

(Just requesting changes to help with my own task management.)

@not-my-profile not-my-profile force-pushed the comment-tags branch 2 times, most recently from 0efda7d to 98a9791 Compare January 3, 2023 02:38
@not-my-profile not-my-profile changed the title Introduce comment-tags setting (and make E501 skip them) Add comment-tags & allow-overlong-lines-for-comment-tags settings Jan 3, 2023
@charliermarsh
Copy link
Member

Will try to get this merged tomorrow.

README.md Outdated Show resolved Hide resolved
@not-my-profile not-my-profile marked this pull request as draft January 3, 2023 22:32
@not-my-profile not-my-profile force-pushed the comment-tags branch 3 times, most recently from b639333 to 9fc74d5 Compare January 3, 2023 23:41
@not-my-profile not-my-profile changed the title Add comment-tags & allow-overlong-lines-for-comment-tags settings Add task-tags & ignore-overlong-task-comments settings Jan 3, 2023
@not-my-profile not-my-profile marked this pull request as ready for review January 3, 2023 23:48
@not-my-profile
Copy link
Contributor Author

not-my-profile commented Jan 3, 2023

I renamed comment-tags to task-tags and allow-overlong-lines-for-comment-tags to ignore-overlong-task-comments as per my reasoning above.

I also split up the PR in three commits with extensive commit messages explaining the reasoning behind the changes. If you merge this, please preserve the individual commits ;)

not-my-profile and others added 3 commits January 4, 2023 06:23
Programmers often leave comments to themselves and others such as:

    # TODO: Use a faster algorithm?

The keywords used to prefix such comments are just a convention and vary
from project to project. Other common keywords include FIXME and HACK.

The keywords in use for the codebase are of interest to ruff because
ruff does also lint comments. For example the ERA lint detects
commented-out code but ignores comments starting with such a keyword.
Previously the ERA lint simply hardcoded the regular expression
TODO|FIXME|XXX to achieve that. This commit introduces a new `task-tags`
setting to make this configurable (and to allow other comment lints to
recognize the same set of keywords).

The term "task tags" has probably been popularized by the Eclipse
IDE.[1] For Python there has been the proposal PEP 350[2], which
referred to such keywords as "codetags". That proposal however has been
rejected. We are choosing the term "task tags" over "code tags" because
the former is more descriptive: a task tag describes a task.

While according to the PEP 350 such keywords are also sometimes used for
non-tasks e.g. NOBUG to describe a well-known problem that will never be
addressed due to design problems or domain limitations, such keywords
are so rare that we are neglecting them here in favor of more
descriptive terminology. The vast majority of such keywords does
describe tasks, so naming the setting "task-tags" is apt.

[1]: https://www.eclipse.org/pdt/help/html/task_tags.htm
[2]: https://peps.python.org/pep-0350/

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This step is split up into a separate commit so
that the following commit has a cleaner diff.
Imagine a .py file containing the following comment:

    # TODO: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
    # do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Since `git grep` only matches individual lines `git grep TODO` would
only output the first line of the comment, cutting off potentially
important information. (git grep currently doesn't support multiline
grepping). Projects using such a workflow therefore probably format
the comment in a single line instead:

    # TODO: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

This commit introduces a setting to accomdate this workflow by making
the line-length checks (`E501`) optionally ignore overlong lines
if they start with a recognized task tag.

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
@charliermarsh charliermarsh merged commit ca48492 into astral-sh:main Jan 4, 2023
@not-my-profile
Copy link
Contributor Author

Thanks for merging ... but I am upset that squashed my carefully crafted commits despite me explicitly requesting you to preserve them. :(

@not-my-profile
Copy link
Contributor Author

Maybe you could revert ca48492 with another commit and then apply my commits individually? I wrote these commit messages to be preserved in the main branch ...

@charliermarsh
Copy link
Member

I do apologize. I tried to preserve them in the PR summary (by replacing it with the first commit message), since the project uses a one-commit-per-PR convention and I'm hesitant to deviate. I eventually want to get to a point such that we have clear PR summaries that get committed as part of the log, but we haven't been rigorous about it and so I've just been omitting messages for consistency. The alternative would've been to break each of those commits into its own PR and create a series of stacked diffs, which would've better lended itself to preserving the commit messages.

If you feel strongly in this case, I can go ahead and re-add to the body. Although I'll note that they do continue to exist in the history on GitHub, and any future archaeologists that are interested in these decisions will be able to find them here.

@not-my-profile
Copy link
Contributor Author

not-my-profile commented Jan 5, 2023

I feel strongly about descriptive commits in general not just in this case. I absolutely do not care about GitHub PR descriptions ... they do not show up when doing a git blame or git logging individual files.

I am afraid that this is quite a dealbreaker for me ... I am not interested in contributing elaborate changes if I have to split them up into separate PRs just to have the commits preserved.

Note that this is not just about preserving the commit messages in the git log but also about having smaller commits with more readable diffs with commit messages that explain the reasoning behind the changes contained in the commit.

@charliermarsh
Copy link
Member

Look, I don't want to be dogmatic. It's very, very reasonable to have a squash-and-merge policy on a codebase -- I can point to a bunch of projects that do this! It has a ton of benefits! -- but I can rebase-and-merge your PRs in the future given that you feel strongly. If, for whatever reason, you choose not to continue contributing to the project, then I earnestly and sincerely thank you for your contributions.

If you're interested in better understanding my perspective, you could Google around for "stacked diffs" (apologies if you're already familiar with this paradigm). It achieves exactly what you've described (smaller, more readable diffs, with commit messages that explain the reasoning), but at the PR level, rather than the commit level.

Separately: regardless of whether you "care" about GitHub PR descriptions, the truth is there's a ton of context in GitHub that isn't captured in the Git log. Look at all the comments on this PR :) From my experience working consistently in large codebases over many years, there's always context that lives in the tool and not in the log. The log is the starting point, not the end point. But, I don't think I'm going to convince you.

@not-my-profile
Copy link
Contributor Author

not-my-profile commented Jan 5, 2023

Thanks for offering to rebase my PRs. Yes of course there is much context in issues and PRs but commit messages give us the opportunity to summarize that context so that the log is a more helpful starting point ... and you perhaps do not even need to look up the PRs to understand the reasoning behind the changes.

I am not familiar with "stacked diffs" ... I just looked into it and I think you rather mean "stacked PRs"? Does this blog post describe what you mean? That blog post does mention some command-line tools for managing stacked PRs ... I am not familiar with them, but I can look into these tools ... can you recommend tools for stacked PRs or do you just manage them manually?

@charliermarsh
Copy link
Member

Heads up: I just reopened the PR as a revert + a cherry-pick of the original commits. I'm happy to avoid squashing your PRs in the future as long as the individual commits remain clear and high-quality as they were in this case. I'm sorry to have gone against your wishes in this case, and I hope we're able to continue working together on Ruff!

@charliermarsh
Copy link
Member

Yes, sorry, "stacked diffs" is a term that comes from a tool called Phabricator, which was a code review tool that spun out of Facebook... But it's analogous to "stacked PRs".

GitHub admittedly doesn't have great tooling to support them and it's been a big area of complaint for people that are used to a stacked PR / stacked diff workflow. (They actually released some improvements like automated retargeting.)

I typically manage them "manually" by setting the upstream of each PR to the PR that comes before, then iteratively rebasing and pushing to update the chain.

Here are some more resources on the concept that I'm describing:

It's possible of course that I'm totally wrong and this isn't a good model for an open source project (vs. a corporate codebase, which I'm more used to). But Dagster, for example, does this -- notice that in the Git history, every commit is a PR.

@andersk
Copy link
Contributor

andersk commented Jan 5, 2023

Unfortunately, since GitHub requires the upstream of each PR to be a branch in the target repository, contributors without write access can’t create stacked PRs at all.

charliermarsh added a commit that referenced this pull request Jan 5, 2023
@charliermarsh
Copy link
Member

Wow, that's a bummer! I hadn't even realized that. I'm too used to working within the context of an org.

@andersk
Copy link
Contributor

andersk commented Jan 5, 2023

Yeah—it seems GitHub hasn’t realized it either, probably for the same reason. 🤦

@not-my-profile
Copy link
Contributor Author

not-my-profile commented Jan 5, 2023

I have not contributed to projects using Phabricator or Gerrit for code review yet, so I am not familiar with this stacked PR workflow. Thanks Anders for that insight ... in that case I think I'll just continue to create PRs with carefully crafted commits. I don't have anything against squashing by default as a convention ... I'm just glad that you're willing to make an exception for contributors like me who like to craft self-contained and well-described individual commits :)

renovate bot added a commit to ixm-one/pytest-cmake-presets that referenced this pull request Jan 5, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [ruff](https://togithub.com/charliermarsh/ruff) | `^0.0.210` ->
`^0.0.211` |
[![age](https://badges.renovateapi.com/packages/pypi/ruff/0.0.211/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/pypi/ruff/0.0.211/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/pypi/ruff/0.0.211/compatibility-slim/0.0.210)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/pypi/ruff/0.0.211/confidence-slim/0.0.210)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>charliermarsh/ruff</summary>

###
[`v0.0.211`](https://togithub.com/charliermarsh/ruff/releases/tag/v0.0.211)

[Compare
Source](https://togithub.com/charliermarsh/ruff/compare/v0.0.210...v0.0.211)

#### What's Changed

- Implement `SIM220` and `SIM221` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1630
- Implement flake8-simplify SIM105 rule by
[@&#8203;messense](https://togithub.com/messense) in
[astral-sh/ruff#1621
- Fix `SIM105` by [@&#8203;harupy](https://togithub.com/harupy) in
[astral-sh/ruff#1633
- Adding my company to the "used in" category of the Readme. by
[@&#8203;colin99d](https://togithub.com/colin99d) in
[astral-sh/ruff#1631
- Implement flake8-bandit rule `S103` by
[@&#8203;edgarrmondragon](https://togithub.com/edgarrmondragon) in
[astral-sh/ruff#1636
- Rename flake8-bandit rules from plugins to checks by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1637
- Tweak Yoda condition message by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1638
- Note a few more incompatibilities by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1639
- Add task-tags & ignore-overlong-task-comments settings by
[@&#8203;not-my-profile](https://togithub.com/not-my-profile) in
[astral-sh/ruff#1550
- Add badge JSON by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1641
- Add Ruff badge to README by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1642
- DRY up unused import removal code by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1643
- Implement builtin import removal by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1645
- Move external licenses to separate directory by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1648
- Implement nested-if detection by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1649
- Implement flake8-bandit rule `S108` by
[@&#8203;edgarrmondragon](https://togithub.com/edgarrmondragon) in
[astral-sh/ruff#1644
- Implement nested with detection (SIM117) by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1651
- Cancel outdated in-progress workflow automatically by
[@&#8203;messense](https://togithub.com/messense) in
[astral-sh/ruff#1652
- Implement flake8-simplify SIM107 by
[@&#8203;messense](https://togithub.com/messense) in
[astral-sh/ruff#1650
- Implement `SIM110` and `SIM111` (conversion to `any` and `all`) by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[astral-sh/ruff#1653

**Full Changelog**:
astral-sh/ruff@v0.0.210...v0.0.211

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/ixm-one/pytest-cmake-presets).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC44MS4wIiwidXBkYXRlZEluVmVyIjoiMzQuODEuMCJ9-->

Signed-off-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants