diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/control_var_used_after_block.py b/crates/ruff_linter/resources/test/fixtures/wemake_python_styleguide/control_var_used_after_block.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/pylint/control_var_used_after_block.py rename to crates/ruff_linter/resources/test/fixtures/wemake_python_styleguide/control_var_used_after_block.py diff --git a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs index 41e4d3285c749..49f5c4bb13d79 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -8,7 +8,7 @@ use crate::codes::Rule; use crate::fix; use crate::rules::{ flake8_builtins, flake8_pyi, flake8_type_checking, flake8_unused_arguments, pep8_naming, - pyflakes, pylint, ruff, + pyflakes, pylint, ruff, wemake_python_styleguide, }; /// Run lint rules over all deferred scopes in the [`SemanticModel`]. @@ -87,10 +87,12 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) { for scope_id in checker.analyze.scopes.iter().rev().copied() { let scope = &checker.semantic.scopes[scope_id]; - // TODO: Put in the right place - // TODO: How to make this run with the global scope outside of a function? if checker.enabled(Rule::ControlVarUsedAfterBlock) { - pylint::rules::control_var_used_after_block(checker, scope, &mut diagnostics); + wemake_python_styleguide::rules::control_var_used_after_block( + checker, + scope, + &mut diagnostics, + ); } if checker.enabled(Rule::UndefinedLocal) { diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 0bb82795ef58e..5428a3a73bc8b 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -1089,8 +1089,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8Logging, "009") => (RuleGroup::Stable, rules::flake8_logging::rules::UndocumentedWarn), // wemake-python-styleguide - // TODO: Put in the right spot - (WemakePythonStyleguide, "441") => (RuleGroup::Stable, rules::pylint::rules::ControlVarUsedAfterBlock), + (WemakePythonStyleguide, "441") => (RuleGroup::Stable, rules::wemake_python_styleguide::rules::ControlVarUsedAfterBlock), _ => return None, }) diff --git a/crates/ruff_linter/src/rules/mod.rs b/crates/ruff_linter/src/rules/mod.rs index 64b0128cae164..cf0034bbdf336 100644 --- a/crates/ruff_linter/src/rules/mod.rs +++ b/crates/ruff_linter/src/rules/mod.rs @@ -57,3 +57,4 @@ pub mod pyupgrade; pub mod refurb; pub mod ruff; pub mod tryceratops; +pub mod wemake_python_styleguide; diff --git a/crates/ruff_linter/src/rules/pylint/mod.rs b/crates/ruff_linter/src/rules/pylint/mod.rs index 1cb7112cc644c..b20b17dac58be 100644 --- a/crates/ruff_linter/src/rules/pylint/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/mod.rs @@ -120,11 +120,6 @@ mod tests { Rule::RedefinedArgumentFromLocal, Path::new("redefined_argument_from_local.py") )] - // TODO: Put this in the right spot - #[test_case( - Rule::ControlVarUsedAfterBlock, - Path::new("control_var_used_after_block.py") - )] #[test_case(Rule::RedefinedLoopName, Path::new("redefined_loop_name.py"))] #[test_case(Rule::ReturnInInit, Path::new("return_in_init.py"))] #[test_case(Rule::TooManyArguments, Path::new("too_many_arguments.py"))] diff --git a/crates/ruff_linter/src/rules/pylint/rules/mod.rs b/crates/ruff_linter/src/rules/pylint/rules/mod.rs index 651b6a4065f02..16f31a9d5a2f1 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/mod.rs @@ -59,8 +59,6 @@ pub(crate) use potential_index_error::*; pub(crate) use property_with_parameters::*; pub(crate) use redeclared_assigned_name::*; pub(crate) use redefined_argument_from_local::*; -// TODO: Put this in the right spot -pub(crate) use control_var_used_after_block::*; pub(crate) use redefined_loop_name::*; pub(crate) use repeated_equality_comparison::*; pub(crate) use repeated_isinstance_calls::*; @@ -163,8 +161,6 @@ mod potential_index_error; mod property_with_parameters; mod redeclared_assigned_name; mod redefined_argument_from_local; -// TODO: Put this in the right spot -mod control_var_used_after_block; mod redefined_loop_name; mod repeated_equality_comparison; mod repeated_isinstance_calls; diff --git a/crates/ruff_linter/src/rules/wemake_python_styleguide/mod.rs b/crates/ruff_linter/src/rules/wemake_python_styleguide/mod.rs new file mode 100644 index 0000000000000..591bbac8e8bcd --- /dev/null +++ b/crates/ruff_linter/src/rules/wemake_python_styleguide/mod.rs @@ -0,0 +1,27 @@ +pub(crate) mod rules; + +#[cfg(test)] +mod tests { + use std::path::Path; + + use anyhow::Result; + use test_case::test_case; + + use crate::registry::Rule; + use crate::test::test_path; + use crate::{assert_messages, settings}; + + #[test_case( + Rule::ControlVarUsedAfterBlock, + Path::new("control_var_used_after_block.py") + )] + fn rules(rule_code: Rule, path: &Path) -> Result<()> { + let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); + let diagnostics = test_path( + Path::new("wemake_python_styleguide").join(path).as_path(), + &settings::LinterSettings::for_rule(rule_code), + )?; + assert_messages!(snapshot, diagnostics); + Ok(()) + } +} diff --git a/crates/ruff_linter/src/rules/pylint/rules/control_var_used_after_block.rs b/crates/ruff_linter/src/rules/wemake_python_styleguide/rules/control_var_used_after_block.rs similarity index 100% rename from crates/ruff_linter/src/rules/pylint/rules/control_var_used_after_block.rs rename to crates/ruff_linter/src/rules/wemake_python_styleguide/rules/control_var_used_after_block.rs diff --git a/crates/ruff_linter/src/rules/wemake_python_styleguide/rules/mod.rs b/crates/ruff_linter/src/rules/wemake_python_styleguide/rules/mod.rs new file mode 100644 index 0000000000000..48ac9e3c886cb --- /dev/null +++ b/crates/ruff_linter/src/rules/wemake_python_styleguide/rules/mod.rs @@ -0,0 +1,3 @@ +pub(crate) use control_var_used_after_block::*; + +mod control_var_used_after_block; diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index b076f80537461..06cf6f4de1f7c 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -1144,12 +1144,6 @@ impl<'a> SemanticModel<'a> { None } - /// TODO - #[inline] - pub fn nodes(&self) -> &Nodes<'a> { - &self.nodes - } - /// Return the [`Stmt`] corresponding to the given [`NodeId`]. #[inline] pub fn node(&self, node_id: NodeId) -> &NodeRef<'a> {