Fix era panic caused by out of bound edition (#4206)

This commit is contained in:
Leiser Fernández Gallo 2023-05-03 15:48:43 +02:00 committed by GitHub
parent d0e3ca29d9
commit 460023a959
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View file

@ -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

View file

@ -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 {

View file

@ -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