Skip to content

Commit

Permalink
Address remaining suggestions and reduce scope of lint by removing ru…
Browse files Browse the repository at this point in the history
…le checks that need contextual information
  • Loading branch information
snowsignal committed Feb 23, 2024
1 parent 0271500 commit dad765d
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 496 deletions.
60 changes: 15 additions & 45 deletions crates/ruff_linter/resources/test/fixtures/ruff/RUF028.py
@@ -1,26 +1,3 @@
# fmt: on
def fmt_off_used_earlier():
if True:
a = 5
with a:
# fmt: off
pass
elif False:
# fmt: off
pass
else:
pass
# fmt: off
if True:
# fmt: off
pass
# fmt: off

# fmt: off

# fmt: on


def fmt_off_between_lists():
test_list = [
# fmt: off
Expand All @@ -29,18 +6,23 @@ def fmt_off_between_lists():
3,
]

# note: the second `fmt: skip`` should be OK
def fmt_skip_on_own_line():
# fmt: skip
pass # fmt: skip


@fmt_on_after_func
@fmt_skip_on_own_line
# fmt: off
@fmt_off_between_lists
def fmt_off_between_decorators():
# fmt: skip
pass

def fmt_on_trailing():
# fmt: off
val = 5 # fmt: on
pass
@fmt_off_between_decorators
# fmt: off
@fmt_off_between_lists
class FmtOffBetweenClassDecorators:
...

def fmt_off_in_else():
x = [1, 2, 3]
Expand All @@ -51,7 +33,7 @@ def fmt_off_in_else():
print("done")
while False:
print("while")
# fmt: on
# fmt: off
# fmt: off
else:
print("done")
Expand All @@ -62,19 +44,7 @@ def fmt_off_in_else():
else:
print("expected")

def dangling_fmt_off():
pass
# fmt: off

def dangling_fmt_off2():
if True:
if True:
pass
# fmt: off
else:
pass
# fmt: off
# fmt: off
else:
pass
def fmt_on_trailing():
# fmt: off
val = 5 # fmt: on
pass # fmt: on
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/analyze/module.rs
Expand Up @@ -9,7 +9,7 @@ pub(crate) fn module(suite: &Suite, checker: &mut Checker) {
if checker.enabled(Rule::FStringDocstring) {
flake8_bugbear::rules::f_string_docstring(checker, suite);
}
if checker.enabled(Rule::IgnoredFormatterNOQA) {
ruff::rules::ignored_formatter_noqa(checker, suite);
if checker.enabled(Rule::InvalidFormatterSuppressionComment) {
ruff::rules::ignored_formatter_suppression_comment(checker, suite);
}
}
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/codes.rs
Expand Up @@ -945,7 +945,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Ruff, "025") => (RuleGroup::Preview, rules::ruff::rules::UnnecessaryDictComprehensionForIterable),
(Ruff, "026") => (RuleGroup::Preview, rules::ruff::rules::DefaultFactoryKwarg),
(Ruff, "027") => (RuleGroup::Preview, rules::ruff::rules::MissingFStringSyntax),
(Ruff, "028") => (RuleGroup::Preview, rules::ruff::rules::IgnoredFormatterNOQA),
(Ruff, "028") => (RuleGroup::Preview, rules::ruff::rules::InvalidFormatterSuppressionComment),
(Ruff, "100") => (RuleGroup::Stable, rules::ruff::rules::UnusedNOQA),
(Ruff, "200") => (RuleGroup::Stable, rules::ruff::rules::InvalidPyprojectToml),
#[cfg(feature = "test-rules")]
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/rules/ruff/mod.rs
Expand Up @@ -49,7 +49,7 @@ mod tests {
#[test_case(Rule::MissingFStringSyntax, Path::new("RUF027_0.py"))]
#[test_case(Rule::MissingFStringSyntax, Path::new("RUF027_1.py"))]
#[test_case(Rule::MissingFStringSyntax, Path::new("RUF027_2.py"))]
#[test_case(Rule::IgnoredFormatterNOQA, Path::new("RUF028.py"))]
#[test_case(Rule::InvalidFormatterSuppressionComment, Path::new("RUF028.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Expand Down

0 comments on commit dad765d

Please sign in to comment.