Skip to content

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

Merged
charliermarsh merged 4 commits intoastral-sh:mainfrom
diceroll123:fix-ruf100-panic
Apr 1, 2024
Merged

[ruff] Fix panic in unused # noqa removal with multi-byte space (RUF100)#10682
charliermarsh merged 4 commits intoastral-sh:mainfrom
diceroll123:fix-ruf100-panic

Conversation

@diceroll123
Copy link
Copy Markdown
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

@github-actions
Copy link
Copy Markdown
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
Copy Markdown
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
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