-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[pyupgrade
] Do not report when a UTF-8 comment is followed by a non-UTF-8 one (UP009
)
#14728
Conversation
…-UTF-8 one (`UP009`)
|
crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should address the case when there are multiple coding comments (that might also be on lines other than the first two)
crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, thanks for implementing the count_lines
method!
There's one more edge case that needs handling
#! /usr/bin/env/python
# -*- coding: utf-8 -*-
# -*- coding: ascii -*-
The second comment gets flagged as unnecessary, which is incorrect because removing it would change the encoding to ascii
crates/ruff_linter/resources/test/fixtures/pyupgrade/UP009_utf8_utf8_other.py
Outdated
Show resolved
Hide resolved
Cases to handle, as a table:
|
@InSyncWithFoo what's the status of this PR? Is it ready for re-review? |
@MichaReiser It is. Please do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the feedback.
The rule currently incorrectly flags the following comments:
x = 10
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
x = 10
# -*- coding: utf-8 -*-
I think we need to make the comment_ranges
iterator more stateful. It should never return Some
after it has seen any non-comment. It might be worth implementing a custom iterator and tracking some internal state.
…-UTF-8 one (`UP009`) (astral-sh#14728) ## Summary Resolves astral-sh#14704. ## Test Plan `cargo nextest run` and `cargo insta test`. --------- Co-authored-by: Micha Reiser <[email protected]>
Summary
Resolves #14704.
Test Plan
cargo nextest run
andcargo insta test
.