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

[ruff] Fix panic in unused # noqa removal with multi-byte space (RUF100) #10682

Merged
merged 4 commits into from Apr 1, 2024

Conversation

diceroll123
Copy link
Contributor

Summary

Currently, this line assumes that the noqa comment begins with an octothorpe followed by a space. (# ) With anyone's random code, this of course is not always true.

When there's a multi-byte character after the leading octothorpe, such as \u0085, we try slicing from within the character, causing a panic.

To fix this, the logic has been changed to remove unused noqa directives and keep any trailing comments, or removing the whole comment if the comment is just the unused noqa

Fixes #10097.

Test Plan

cargo test

Copy link
Contributor

github-actions bot commented Mar 31, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@diceroll123 diceroll123 changed the title Fix panic in RUF100 [ruff] - Fix panic in (RUF100) Mar 31, 2024
@diceroll123 diceroll123 changed the title [ruff] - Fix panic in (RUF100) [ruff] - Fix panic (RUF100) Mar 31, 2024
@charliermarsh charliermarsh self-requested a review April 1, 2024 00:42
@charliermarsh charliermarsh self-assigned this Apr 1, 2024
@charliermarsh charliermarsh added the bug Something isn't working label Apr 1, 2024
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.

Thanks!

@charliermarsh charliermarsh changed the title [ruff] - Fix panic (RUF100) [ruff] Fix panic in unused # noqa removal with multi-byte space (RUF100) Apr 1, 2024
@charliermarsh charliermarsh added the fuzzer Surfaced via fuzzing. label Apr 1, 2024
@charliermarsh charliermarsh enabled auto-merge (squash) April 1, 2024 00:52
@charliermarsh charliermarsh merged commit f6b6f0d into astral-sh:main Apr 1, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzer Surfaced via fuzzing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule RUF100 cause panic
2 participants