From f319531632ecb683051891637be56ec58d470993 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Sat, 4 Jan 2025 12:52:08 +0100 Subject: [PATCH] Make unreachable a test rule for now (#15252) --- .github/workflows/ci.yaml | 2 +- crates/ruff_linter/src/checkers/ast/analyze/statement.rs | 1 + crates/ruff_linter/src/codes.rs | 1 + crates/ruff_linter/src/rules/pylint/rules/mod.rs | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2f2078b908e6d..83502cfc55dff 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -386,7 +386,7 @@ jobs: - name: "Install Rust toolchain" run: rustup component add rustfmt - uses: Swatinem/rust-cache@v2 - - run: ./scripts/add_rule.py --name DoTheThing --prefix PL --code C0999 --linter pylint + - run: ./scripts/add_rule.py --name DoTheThing --prefix F --code 999 --linter pyflakes - run: cargo check - run: cargo fmt --all --check - run: | diff --git a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs index a780c4e3ab5a1..b9b55757178e9 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs @@ -366,6 +366,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { if checker.enabled(Rule::AsyncFunctionWithTimeout) { flake8_async::rules::async_function_with_timeout(checker, function_def); } + #[cfg(any(feature = "test-rules", test))] if checker.enabled(Rule::UnreachableCode) { checker .diagnostics diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 30bc6949f8c88..b0d2efb9a90cf 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -268,6 +268,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "R6104") => (RuleGroup::Preview, rules::pylint::rules::NonAugmentedAssignment), (Pylint, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership), (Pylint, "R6301") => (RuleGroup::Preview, rules::pylint::rules::NoSelfUse), + #[cfg(any(feature = "test-rules", test))] (Pylint, "W0101") => (RuleGroup::Preview, rules::pylint::rules::UnreachableCode), (Pylint, "W0108") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryLambda), (Pylint, "W0177") => (RuleGroup::Preview, rules::pylint::rules::NanComparison), diff --git a/crates/ruff_linter/src/rules/pylint/rules/mod.rs b/crates/ruff_linter/src/rules/pylint/rules/mod.rs index 8d019d0887a48..f0f809ec4279f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/mod.rs @@ -95,6 +95,7 @@ pub(crate) use unnecessary_direct_lambda_call::*; pub(crate) use unnecessary_dunder_call::*; pub(crate) use unnecessary_lambda::*; pub(crate) use unnecessary_list_index_lookup::*; +#[cfg(any(feature = "test-rules", test))] pub(crate) use unreachable::*; pub(crate) use unspecified_encoding::*; pub(crate) use useless_else_on_loop::*; @@ -202,6 +203,7 @@ mod unnecessary_direct_lambda_call; mod unnecessary_dunder_call; mod unnecessary_lambda; mod unnecessary_list_index_lookup; +#[cfg(any(feature = "test-rules", test))] mod unreachable; mod unspecified_encoding; mod useless_else_on_loop;