Move check validation into add_check

This commit is contained in:
Charlie Marsh 2022-10-14 17:05:37 -04:00
parent e73f13473d
commit 87ab4e5c16
2 changed files with 16 additions and 7 deletions

View File

@ -1392,6 +1392,15 @@ impl<'a> Checker<'a> {
self.checks.push(check); 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) { fn push_parent(&mut self, parent: &'a Stmt) {
self.parent_stack.push(self.parents.len()); self.parent_stack.push(self.parents.len());
self.parents.push(parent); self.parents.push(parent);

View File

@ -236,13 +236,13 @@ pub fn blank_before_after_class(checker: &mut Checker, definition: &Definition)
.skip(1) .skip(1)
.take_while(|line| line.trim().is_empty()) .take_while(|line| line.trim().is_empty())
.count(); .count();
if blank_lines_before != 0 if blank_lines_before != 0 {
&& checker.settings.enabled.contains(&CheckCode::D211) checker.add_check_if(&CheckCode::D211, || {
{ Check::new(
checker.add_check(Check::new(
CheckKind::NoBlankLineBeforeClass(blank_lines_before), CheckKind::NoBlankLineBeforeClass(blank_lines_before),
helpers::range_for(docstring), helpers::range_for(docstring),
)); )
});
} }
if blank_lines_before != 1 if blank_lines_before != 1
&& checker.settings.enabled.contains(&CheckCode::D203) && checker.settings.enabled.contains(&CheckCode::D203)