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

[flake8-todo] - Align TD003 with the VSCode Github PR extension #9627

Conversation

MartinBernstorff
Copy link
Contributor

@MartinBernstorff MartinBernstorff commented Jan 23, 2024

Summary

The GitHub VSCode extension supports automatically creating an issue from a comment with two formats, selectable under the setting githubIssues.createInsertFormat.

# TODO: https://github.com/astral-sh/ruff/issues/8061 Todo description
# TODO: #8061 Todo description

As discussed in #8061, this PR expands TD003 to consider those two formats valid.

Design considerations

Since the new behaviour is single-line analysis, I considered adding it to the static_errors fn, but decided co-locating all the TD003 code instead made more sense.

Test Plan

The two formats were added to TD003.py and did not raise errors. I'm somewhat concerned that the new regex patterns could induce false negatives, and would love reviewer feedback on that!

@MartinBernstorff MartinBernstorff changed the title Align TD003 with the VSCode Github PR extension [flake8-todo] Align TD003 with the VSCode Github PR extension Jan 23, 2024
@MartinBernstorff MartinBernstorff changed the title [flake8-todo] Align TD003 with the VSCode Github PR extension [flake8-todo] - Align TD003 with the VSCode Github PR extension Jan 23, 2024
Copy link
Contributor

github-actions bot commented Jan 23, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+678 -698 violations, +0 -0 fixes in 3 projects; 40 projects unchanged)

apache/airflow (+275 -276 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-preview --select ALL

+ airflow/api_connexion/schemas/dag_schema.py:100:55: TD003 Missing issue link for this TODO
- airflow/api_connexion/schemas/dag_schema.py:100:55: TD003 Missing issue link on the line following this TODO
+ airflow/cli/cli_config.py:239:6: TD003 Missing issue link for this TODO
- airflow/cli/cli_config.py:239:6: TD003 Missing issue link on the line following this TODO
+ airflow/cli/cli_config.py:579:3: TD003 Missing issue link for this TODO
- airflow/cli/cli_config.py:579:3: TD003 Missing issue link on the line following this TODO
+ airflow/cli/cli_config.py:595:3: TD003 Missing issue link for this TODO
- airflow/cli/cli_config.py:595:3: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:191:11: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:191:11: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:237:15: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:237:15: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:472:7: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:472:7: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:689:11: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:689:11: TD003 Missing issue link on the line following this TODO
+ airflow/compat/functools.pyi:20:3: TD003 Missing issue link for this TODO
- airflow/compat/functools.pyi:20:3: TD003 Missing issue link on the line following this TODO
+ airflow/dag_processing/manager.py:1293:7: TD003 Missing issue link for this TODO
- airflow/dag_processing/manager.py:1293:7: TD003 Missing issue link on the line following this TODO
... 531 additional changes omitted for project

bokeh/bokeh (+180 -198 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-preview --select ALL

+ examples/integration/layout/plot_fixed_frame_size.py:38:3: TD003 Missing issue link for this TODO
- examples/integration/layout/plot_fixed_frame_size.py:38:3: TD003 Missing issue link on the line following this TODO
+ examples/models/legends.py:53:11: TD003 Missing issue link for this TODO
- examples/models/legends.py:53:11: TD003 Missing issue link on the line following this TODO
+ examples/server/app/simple_hdf5/main.py:50:3: TD003 Missing issue link for this TODO
- examples/server/app/simple_hdf5/main.py:50:3: TD003 Missing issue link on the line following this TODO
+ release/credentials.py:77:7: TD003 Missing issue link for this TODO
- release/credentials.py:77:7: TD003 Missing issue link on the line following this TODO
+ release/credentials.py:84:7: TD003 Missing issue link for this TODO
- release/credentials.py:84:7: TD003 Missing issue link on the line following this TODO
+ src/bokeh/application/application.py:187:15: TD003 Missing issue link for this TODO
- src/bokeh/application/application.py:187:15: TD003 Missing issue link on the line following this TODO
+ src/bokeh/application/handlers/code.py:168:11: TD003 Missing issue link for this TODO
... 365 additional changes omitted for project

zulip/zulip (+223 -224 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-preview --select ALL

+ analytics/lib/counts.py:122:7: TD003 Missing issue link for this TODO
- analytics/lib/counts.py:122:7: TD003 Missing issue link on the line following this TODO
+ analytics/lib/counts.py:266:11: TD003 Missing issue link for this TODO
- analytics/lib/counts.py:266:11: TD003 Missing issue link on the line following this TODO
+ analytics/management/commands/populate_analytics_db.py:74:11: TD003 Missing issue link for this TODO
- analytics/management/commands/populate_analytics_db.py:74:11: TD003 Missing issue link on the line following this TODO
+ analytics/views/stats.py:111:11: TD003 Missing issue link for this TODO
- analytics/views/stats.py:111:11: TD003 Missing issue link on the line following this TODO
+ analytics/views/stats.py:451:11: TD003 Missing issue link for this TODO
- analytics/views/stats.py:451:11: TD003 Missing issue link on the line following this TODO
+ corporate/lib/stripe.py:1343:11: TD003 Missing issue link for this TODO
- corporate/lib/stripe.py:1343:11: TD003 Missing issue link on the line following this TODO
+ corporate/lib/stripe.py:1923:11: TD003 Missing issue link for this TODO
- corporate/lib/stripe.py:1923:11: TD003 Missing issue link on the line following this TODO
+ corporate/lib/stripe.py:2190:15: TD003 Missing issue link for this TODO
- corporate/lib/stripe.py:2190:15: TD003 Missing issue link on the line following this TODO
... 431 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
TD003 1376 678 698 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+678 -698 violations, +0 -0 fixes in 3 projects; 40 projects unchanged)

apache/airflow (+275 -276 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview --select ALL

+ airflow/api_connexion/schemas/dag_schema.py:100:55: TD003 Missing issue link for this TODO
- airflow/api_connexion/schemas/dag_schema.py:100:55: TD003 Missing issue link on the line following this TODO
+ airflow/cli/cli_config.py:239:6: TD003 Missing issue link for this TODO
- airflow/cli/cli_config.py:239:6: TD003 Missing issue link on the line following this TODO
+ airflow/cli/cli_config.py:579:3: TD003 Missing issue link for this TODO
- airflow/cli/cli_config.py:579:3: TD003 Missing issue link on the line following this TODO
+ airflow/cli/cli_config.py:595:3: TD003 Missing issue link for this TODO
- airflow/cli/cli_config.py:595:3: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:191:11: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:191:11: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:237:15: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:237:15: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:472:7: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:472:7: TD003 Missing issue link on the line following this TODO
+ airflow/cli/commands/task_command.py:689:11: TD003 Missing issue link for this TODO
- airflow/cli/commands/task_command.py:689:11: TD003 Missing issue link on the line following this TODO
+ airflow/compat/functools.pyi:20:3: TD003 Missing issue link for this TODO
- airflow/compat/functools.pyi:20:3: TD003 Missing issue link on the line following this TODO
+ airflow/dag_processing/manager.py:1293:7: TD003 Missing issue link for this TODO
- airflow/dag_processing/manager.py:1293:7: TD003 Missing issue link on the line following this TODO
... 531 additional changes omitted for project

bokeh/bokeh (+180 -198 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview --select ALL

+ examples/integration/layout/plot_fixed_frame_size.py:38:3: TD003 Missing issue link for this TODO
- examples/integration/layout/plot_fixed_frame_size.py:38:3: TD003 Missing issue link on the line following this TODO
+ examples/models/legends.py:53:11: TD003 Missing issue link for this TODO
- examples/models/legends.py:53:11: TD003 Missing issue link on the line following this TODO
+ examples/server/app/simple_hdf5/main.py:50:3: TD003 Missing issue link for this TODO
- examples/server/app/simple_hdf5/main.py:50:3: TD003 Missing issue link on the line following this TODO
+ release/credentials.py:77:7: TD003 Missing issue link for this TODO
- release/credentials.py:77:7: TD003 Missing issue link on the line following this TODO
+ release/credentials.py:84:7: TD003 Missing issue link for this TODO
- release/credentials.py:84:7: TD003 Missing issue link on the line following this TODO
+ src/bokeh/application/application.py:187:15: TD003 Missing issue link for this TODO
- src/bokeh/application/application.py:187:15: TD003 Missing issue link on the line following this TODO
+ src/bokeh/application/handlers/code.py:168:11: TD003 Missing issue link for this TODO
... 365 additional changes omitted for project

zulip/zulip (+223 -224 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview --select ALL

+ analytics/lib/counts.py:122:7: TD003 Missing issue link for this TODO
- analytics/lib/counts.py:122:7: TD003 Missing issue link on the line following this TODO
+ analytics/lib/counts.py:266:11: TD003 Missing issue link for this TODO
- analytics/lib/counts.py:266:11: TD003 Missing issue link on the line following this TODO
+ analytics/management/commands/populate_analytics_db.py:74:11: TD003 Missing issue link for this TODO
- analytics/management/commands/populate_analytics_db.py:74:11: TD003 Missing issue link on the line following this TODO
+ analytics/views/stats.py:111:11: TD003 Missing issue link for this TODO
- analytics/views/stats.py:111:11: TD003 Missing issue link on the line following this TODO
+ analytics/views/stats.py:451:11: TD003 Missing issue link for this TODO
- analytics/views/stats.py:451:11: TD003 Missing issue link on the line following this TODO
+ corporate/lib/stripe.py:1343:11: TD003 Missing issue link for this TODO
- corporate/lib/stripe.py:1343:11: TD003 Missing issue link on the line following this TODO
+ corporate/lib/stripe.py:1923:11: TD003 Missing issue link for this TODO
- corporate/lib/stripe.py:1923:11: TD003 Missing issue link on the line following this TODO
+ corporate/lib/stripe.py:2190:15: TD003 Missing issue link for this TODO
- corporate/lib/stripe.py:2190:15: TD003 Missing issue link on the line following this TODO
... 431 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
TD003 1376 678 698 0 0

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Thanks for putting together this PR!

It seems that there are lot of violations which got removed from the ecosystem checks. For example, https://github.com/apache/airflow/blob/c0f76013917ee57b3cc2cebcf08e4421143eefc7/airflow/dag_processing/manager.py#L1293 isn't being triggered now. I think the issue might be the re-ordering of the code as there's an issue link after a couple of lines of the TODO in the source code.

Comment on lines 227 to 233
r"^#\s*(http|https)://.*", // issue link
r"^#\s*\d+$", // issue code - like "003"
r"^#\s*[A-Z]{1,6}\-?\d+$", // issue code - like "TD003"
r"^#.*(http|https)://.*", // issue link
r"^#.*#\d+", // issue code - like "#003"
r"^#\s\d+", // issue code - like "003"
r"^#\s[A-Z]{1,6}\-?\d+", // issue code - like "TD003"
Copy link
Member

Choose a reason for hiding this comment

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

Is it correct that the reason you removed the \s from the "issue link" regex is so that the link can be anywhere in the comment?

Also, can we keep the asterisk for \s* so that there can be any number of whitespace instead of just one? Is there a reason you removed them?

Copy link
Contributor Author

@MartinBernstorff MartinBernstorff Jan 26, 2024

Choose a reason for hiding this comment

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

Is it correct that the reason you removed the \s from the "issue link" regex is so that the link can be anywhere in the comment?

Yep, absolutely!

Also, can we keep the asterisk for \s* so that there can be any number of whitespace instead of just one? Is there a reason you removed them?

I removed 'em because I'd consider # TODO incorrect, but if we were to enforce that, it should be through TD007. I've re-added them.

Comment on lines 48 to 49
32 |
33 | # TODO: https://github.com/astral-sh/ruff/issues/8061 This comment also has a link
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test case for #002 variant as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! It's at the bottom of TD003.py, but doesn't error, so is not in the .snap. The link-case is included due to being within the context of the non-linnk failing example :-)

@dhruvmanila dhruvmanila added the rule Implementing or modifying a lint rule label Jan 24, 2024
@MartinBernstorff
Copy link
Contributor Author

Thanks for putting together this PR!

It seems that there are lot of violations which got removed from the ecosystem checks. For example, https://github.com/apache/airflow/blob/c0f76013917ee57b3cc2cebcf08e4421143eefc7/airflow/dag_processing/manager.py#L1293 isn't being triggered now. I think the issue might be the re-ordering of the code as there's an issue link after a couple of lines of the TODO in the source code.

This is a really good point! I'm implementing a solution that should make the changes smaller in the ecosystem.

That said, I think this opens up a discussion about desirable behaviour. E.g. the linked comment does, in fact, contain an issue link. It just doesn't occur on the same or the next line. Would we want to support that, or is the false-negative rate perhaps too high?

I'd lean towards "on same or next line", but would love to hear your thoughts!

Copy link

codspeed-hq bot commented Jan 26, 2024

CodSpeed Performance Report

Merging #9627 will not alter performance

Comparing MartinBernstorff:mbern/8061/td003-support-vscode-github-syntax (18df98a) with main (45f01e7)

Summary

✅ 32 untouched benchmarks

@MartinBernstorff
Copy link
Contributor Author

The large amount of ecosystem changes in the previous version was largely due to changing the regex set.

I've had to split into two regex sets to keep the ecosystem changes small.

Unsure if that should give such a large change to performance, would love some input here.

Let me know what you think!

@dhruvmanila
Copy link
Member

I'd lean towards "on same or next line", but would love to hear your thoughts!

Yeah, I'm thinking in the same direction. It seems like the extension only provides the code action to create the issue if the text / link isn't on the same line. So, your intuition to making it work for same or next line should reduce the false negative rate.

@simonpercivall
Copy link

This seems to have gotten a bit stale, but it would still be very nice to get this. Can I assist in any way to help push this forward?

@MartinBernstorff
Copy link
Contributor Author

Hi @simonpercivall! Absolutely, it's on me for not finishing this. I'm not sure I ever will, so from my end you're free to fork/replace this PR 👍

@dhruvmanila
Copy link
Member

(I've merged the latest main in this PR, @simonpercivall if you're interested feel free to work on top of this or start a new, whatever seems easier for you.)

@dylwil3
Copy link
Collaborator

dylwil3 commented Jan 15, 2025

Gonna move this work to #15519 so that we can work off of main. (I tried rebasing first but was not confident in some of the messier conflict resolutions, so it seemed cleaner to do it this way). @MartinBernstorff thank you for the contribution, and sorry for the long delay in resolution!

@dylwil3 dylwil3 closed this Jan 15, 2025
dylwil3 added a commit that referenced this pull request Jan 15, 2025
…sing-todo-link` (`TD003`) (#15519)

## Summary
Allow links to issues that appear on the same line as the TODO
directive, if they conform to the format that VSCode's GitHub PR
extension produces.

Revival of #9627 (the branch was stale enough that rebasing was a lot
harder than just making the changes anew). Credit should go to the
author of that PR though.

Closes #8061

Co-authored-by: Martin Bernstorff <martinbernstorff@gmail.com>
@MartinBernstorff
Copy link
Contributor Author

@dylwil3 Absolutely no worries, I didn't follow up either, and super happy to see this merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants