Skip to content

Commit

Permalink
Move to wemake_python_styleguide ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Jun 5, 2024
1 parent 0e491b3 commit 9ca72a6
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 21 deletions.
10 changes: 6 additions & 4 deletions crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ pub mod pyupgrade;
pub mod refurb;
pub mod ruff;
pub mod tryceratops;
pub mod wemake_python_styleguide;
5 changes: 0 additions & 5 deletions crates/ruff_linter/src/rules/pylint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
4 changes: 0 additions & 4 deletions crates/ruff_linter/src/rules/pylint/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions crates/ruff_linter/src/rules/wemake_python_styleguide/mod.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) use control_var_used_after_block::*;

mod control_var_used_after_block;
6 changes: 0 additions & 6 deletions crates/ruff_python_semantic/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 9ca72a6

Please sign in to comment.