-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to the new rule architecture (#4589)
- Loading branch information
1 parent
fcdc7bd
commit 4233f6e
Showing
108 changed files
with
2,741 additions
and
2,373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub(crate) use commented_out_code::{commented_out_code, CommentedOutCode}; | ||
|
||
mod commented_out_code; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use ruff_python_semantic::model::SemanticModel; | ||
use rustpython_parser::ast::Expr; | ||
|
||
pub(super) fn is_sys(model: &SemanticModel, expr: &Expr, target: &str) -> bool { | ||
model | ||
.resolve_call_path(expr) | ||
.map_or(false, |call_path| call_path.as_slice() == ["sys", target]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pub(crate) use compare::{ | ||
compare, SysVersionCmpStr10, SysVersionCmpStr3, SysVersionInfo0Eq3, SysVersionInfo1CmpInt, | ||
SysVersionInfoMinorCmpInt, | ||
}; | ||
pub(crate) use name_or_attribute::{name_or_attribute, SixPY3}; | ||
pub(crate) use subscript::{ | ||
subscript, SysVersion0, SysVersion2, SysVersionSlice1, SysVersionSlice3, | ||
}; | ||
|
||
mod compare; | ||
mod name_or_attribute; | ||
mod subscript; |
29 changes: 29 additions & 0 deletions
29
crates/ruff/src/rules/flake8_2020/rules/name_or_attribute.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use rustpython_parser::ast::{Expr, Ranged}; | ||
|
||
use ruff_diagnostics::{Diagnostic, Violation}; | ||
use ruff_macros::{derive_message_formats, violation}; | ||
|
||
use crate::checkers::ast::Checker; | ||
|
||
#[violation] | ||
pub struct SixPY3; | ||
|
||
impl Violation for SixPY3 { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("`six.PY3` referenced (python4), use `not six.PY2`") | ||
} | ||
} | ||
|
||
/// YTT202 | ||
pub(crate) fn name_or_attribute(checker: &mut Checker, expr: &Expr) { | ||
if checker | ||
.semantic_model() | ||
.resolve_call_path(expr) | ||
.map_or(false, |call_path| call_path.as_slice() == ["six", "PY3"]) | ||
{ | ||
checker | ||
.diagnostics | ||
.push(Diagnostic::new(SixPY3, expr.range())); | ||
} | ||
} |
Oops, something went wrong.