mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
Fix era panic caused by out of bound edition (#4206)
This commit is contained in:
parent
d0e3ca29d9
commit
460023a959
3 changed files with 22 additions and 5 deletions
|
@ -14,3 +14,8 @@ def foo(x, y, z):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#import os # noqa: ERA001
|
#import os # noqa: ERA001
|
||||||
|
|
||||||
|
|
||||||
|
class A():
|
||||||
|
pass
|
||||||
|
# b = c
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ruff_text_size::{TextLen, TextRange};
|
use ruff_text_size::TextRange;
|
||||||
|
|
||||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit};
|
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
@ -58,10 +58,7 @@ pub fn commented_out_code(
|
||||||
if is_standalone_comment(line) && comment_contains_code(line, &settings.task_tags[..]) {
|
if is_standalone_comment(line) && comment_contains_code(line, &settings.task_tags[..]) {
|
||||||
let mut diagnostic = Diagnostic::new(CommentedOutCode, range);
|
let mut diagnostic = Diagnostic::new(CommentedOutCode, range);
|
||||||
if autofix.into() && settings.rules.should_fix(Rule::CommentedOutCode) {
|
if autofix.into() && settings.rules.should_fix(Rule::CommentedOutCode) {
|
||||||
diagnostic.set_fix(Edit::range_deletion(TextRange::at(
|
diagnostic.set_fix(Edit::range_deletion(locator.full_lines_range(range)));
|
||||||
range.start(),
|
|
||||||
line.text_len(),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
Some(diagnostic)
|
Some(diagnostic)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,4 +91,19 @@ ERA001.py:13:5: ERA001 [*] Found commented-out code
|
||||||
15 14 |
|
15 14 |
|
||||||
16 15 | #import os # noqa: ERA001
|
16 15 | #import os # noqa: ERA001
|
||||||
|
|
||||||
|
ERA001.py:21:5: ERA001 [*] Found commented-out code
|
||||||
|
|
|
||||||
|
21 | class A():
|
||||||
|
22 | pass
|
||||||
|
23 | # b = c
|
||||||
|
| ^^^^^^^ ERA001
|
||||||
|
|
|
||||||
|
= help: Remove commented-out code
|
||||||
|
|
||||||
|
ℹ Suggested fix
|
||||||
|
18 18 |
|
||||||
|
19 19 | class A():
|
||||||
|
20 20 | pass
|
||||||
|
21 |- # b = c
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue