mirror of https://github.com/astral-sh/ruff
Move check validation into add_check
This commit is contained in:
parent
e73f13473d
commit
87ab4e5c16
|
|
@ -1392,6 +1392,15 @@ impl<'a> Checker<'a> {
|
|||
self.checks.push(check);
|
||||
}
|
||||
|
||||
pub fn add_check_if<F>(&mut self, code: &CheckCode, f: F)
|
||||
where
|
||||
F: FnOnce() -> Check,
|
||||
{
|
||||
if self.settings.enabled.contains(code) {
|
||||
self.checks.push(f());
|
||||
}
|
||||
}
|
||||
|
||||
fn push_parent(&mut self, parent: &'a Stmt) {
|
||||
self.parent_stack.push(self.parents.len());
|
||||
self.parents.push(parent);
|
||||
|
|
|
|||
|
|
@ -236,13 +236,13 @@ pub fn blank_before_after_class(checker: &mut Checker, definition: &Definition)
|
|||
.skip(1)
|
||||
.take_while(|line| line.trim().is_empty())
|
||||
.count();
|
||||
if blank_lines_before != 0
|
||||
&& checker.settings.enabled.contains(&CheckCode::D211)
|
||||
{
|
||||
checker.add_check(Check::new(
|
||||
CheckKind::NoBlankLineBeforeClass(blank_lines_before),
|
||||
helpers::range_for(docstring),
|
||||
));
|
||||
if blank_lines_before != 0 {
|
||||
checker.add_check_if(&CheckCode::D211, || {
|
||||
Check::new(
|
||||
CheckKind::NoBlankLineBeforeClass(blank_lines_before),
|
||||
helpers::range_for(docstring),
|
||||
)
|
||||
});
|
||||
}
|
||||
if blank_lines_before != 1
|
||||
&& checker.settings.enabled.contains(&CheckCode::D203)
|
||||
|
|
|
|||
Loading…
Reference in New Issue