Skip to content

Commit

Permalink
Avoid running RUF100 rules when code contains syntax errors (#4869)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Jun 5, 2023
1 parent f952bef commit e6b00f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crates/ruff/src/checkers/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ pub(crate) fn check_noqa(
locator: &Locator,
comment_ranges: &[TextRange],
noqa_line_for: &NoqaMapping,
analyze_directives: bool,
settings: &Settings,
) -> Vec<usize> {
let enforce_noqa = settings.rules.enabled(Rule::UnusedNOQA);

// Identify any codes that are globally exempted (within the current file).
let exemption = noqa::file_exemption(locator.contents(), comment_ranges);

Expand Down Expand Up @@ -93,7 +92,7 @@ pub(crate) fn check_noqa(
}

// Enforce that the noqa directive was actually used (RUF100).
if enforce_noqa {
if analyze_directives && settings.rules.enabled(Rule::UnusedNOQA) {
for line in noqa_directives.lines() {
match &line.directive {
Directive::All(leading_spaces, noqa_range, trailing_spaces) => {
Expand Down
1 change: 1 addition & 0 deletions crates/ruff/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ pub fn check_path(
locator,
indexer.comment_ranges(),
&directives.noqa_line_for,
error.is_none(),
settings,
);
if noqa.into() {
Expand Down

0 comments on commit e6b00f0

Please sign in to comment.