mirror of https://github.com/astral-sh/ruff
Only scan checks once in check_lines (#679)
This commit is contained in:
parent
560c00ff9d
commit
bf7bf7aa17
|
|
@ -47,6 +47,12 @@ pub fn check_lines(
|
||||||
let mut line_checks = vec![];
|
let mut line_checks = vec![];
|
||||||
let mut ignored = vec![];
|
let mut ignored = vec![];
|
||||||
|
|
||||||
|
checks.sort_by_key(|check| check.location);
|
||||||
|
let mut checks_iter = checks.iter().enumerate().peekable();
|
||||||
|
if let Some((_index, check)) = checks_iter.peek() {
|
||||||
|
assert!(check.location.row() >= 1);
|
||||||
|
}
|
||||||
|
|
||||||
let lines: Vec<&str> = contents.lines().collect();
|
let lines: Vec<&str> = contents.lines().collect();
|
||||||
for (lineno, line) in lines.iter().enumerate() {
|
for (lineno, line) in lines.iter().enumerate() {
|
||||||
// Grab the noqa (logical) line number for the current (physical) line.
|
// Grab the noqa (logical) line number for the current (physical) line.
|
||||||
|
|
@ -88,9 +94,9 @@ pub fn check_lines(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any ignored checks.
|
// Remove any ignored checks.
|
||||||
// TODO(charlie): Only validate checks for the current line.
|
while let Some((index, check)) =
|
||||||
for (index, check) in checks.iter().enumerate() {
|
checks_iter.next_if(|(_index, check)| check.location.row() == lineno + 1)
|
||||||
if check.location.row() == lineno + 1 {
|
{
|
||||||
let noqa = noqa_directives
|
let noqa = noqa_directives
|
||||||
.entry(noqa_lineno)
|
.entry(noqa_lineno)
|
||||||
.or_insert_with(|| (noqa::extract_noqa_directive(lines[noqa_lineno]), vec![]));
|
.or_insert_with(|| (noqa::extract_noqa_directive(lines[noqa_lineno]), vec![]));
|
||||||
|
|
@ -109,7 +115,6 @@ pub fn check_lines(
|
||||||
(Directive::None, _) => {}
|
(Directive::None, _) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Enforce line length violations (E501).
|
// Enforce line length violations (E501).
|
||||||
if enforce_line_too_long {
|
if enforce_line_too_long {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue