diff --git a/src/check_ast.rs b/src/check_ast.rs index ae6b762781..b069a25415 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -1392,6 +1392,15 @@ impl<'a> Checker<'a> { self.checks.push(check); } + pub fn add_check_if(&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); diff --git a/src/docstrings/docstring_plugins.rs b/src/docstrings/docstring_plugins.rs index 670cfb2e34..a33fca204b 100644 --- a/src/docstrings/docstring_plugins.rs +++ b/src/docstrings/docstring_plugins.rs @@ -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)