mirror of https://github.com/astral-sh/ruff
Theres enough here for a proposal
This commit is contained in:
parent
3295ccfbc4
commit
a4432102f1
|
|
@ -154,19 +154,6 @@ impl<'a> Checker<'a> {
|
|||
rules.push(pyupgrade::rules::type_of_primitive);
|
||||
}
|
||||
|
||||
// This is closest to Rome.
|
||||
let mut analysis_rules: Vec<RegisteredAstRule<ast::ExprCall>> = vec![];
|
||||
|
||||
// flake8-django
|
||||
if settings.rules.enabled(Rule::DjangoLocalsInRenderFunction) {
|
||||
analysis_rules.push(RegisteredAstRule::new::<DjangoLocalsInRenderFunction>());
|
||||
}
|
||||
|
||||
// pyupgrade
|
||||
if settings.rules.enabled(Rule::TypeOfPrimitive) {
|
||||
analysis_rules.push(RegisteredAstRule::new::<TypeOfPrimitive>());
|
||||
}
|
||||
|
||||
let mut _analysis_rules: Vec<AstRuleExecutor<ast::ExprCall>> = vec![];
|
||||
|
||||
// flake8-django
|
||||
|
|
@ -175,17 +162,17 @@ impl<'a> Checker<'a> {
|
|||
}
|
||||
|
||||
// We _can_ do this which is nice.
|
||||
for (rule, analyzer) in [
|
||||
(
|
||||
|
||||
// This is closest to Rome.
|
||||
let mut analysis_rules: Vec<RegisteredAstRule<ast::ExprCall>> = vec![];
|
||||
|
||||
for analyzer in [
|
||||
RegisteredAstRule::new::<DjangoLocalsInRenderFunction>(
|
||||
Rule::DjangoLocalsInRenderFunction,
|
||||
RegisteredAstRule::new::<DjangoLocalsInRenderFunction>(),
|
||||
),
|
||||
(
|
||||
Rule::TypeOfPrimitive,
|
||||
RegisteredAstRule::new::<TypeOfPrimitive>(),
|
||||
),
|
||||
RegisteredAstRule::new::<TypeOfPrimitive>(Rule::TypeOfPrimitive),
|
||||
] {
|
||||
if settings.rules.enabled(rule) {
|
||||
if settings.rules.enabled(analyzer.rule) {
|
||||
analysis_rules.push(analyzer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
use ruff_diagnostics::Diagnostic;
|
||||
|
||||
use crate::checkers::ast::RuleContext;
|
||||
use crate::registry::Rule;
|
||||
|
||||
pub(crate) struct RegisteredAstRule<T> {
|
||||
pub(crate) run: AstRuleExecutor<T>,
|
||||
pub(crate) rule: Rule,
|
||||
}
|
||||
|
||||
// A nice thing about this is that we can have state that lives in this struct,
|
||||
// and we can pass it to the `run` function... E.g., flake8_bugbear_seen.
|
||||
impl<T> RegisteredAstRule<T> {
|
||||
pub(crate) fn new<R: AstRule<T> + 'static>() -> Self {
|
||||
Self { run: R::run }
|
||||
pub(crate) fn new<R: AstRule<T> + 'static>(rule: Rule) -> Self {
|
||||
Self { run: R::run, rule }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ impl Violation for DjangoLocalsInRenderFunction {
|
|||
}
|
||||
|
||||
impl AstRule<ast::ExprCall> for DjangoLocalsInRenderFunction {
|
||||
fn run(diagnostics: &mut Vec<Diagnostic>, checker: &RuleContext, node: &ast::ExprCall) {
|
||||
locals_in_render_function(diagnostics, checker, node)
|
||||
fn run(diagnostics: &mut Vec<Diagnostic>, context: &RuleContext, node: &ast::ExprCall) {
|
||||
locals_in_render_function(diagnostics, context, node)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue