Skip to content

Commit

Permalink
put dummy def check in a helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoel-bagard committed Apr 10, 2024
1 parent 09d0bdd commit 6751ef1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ enum Follows {
Docstring,
}

impl Follows {
// Allow a function/method to follow a function/method with a dummy body.
const fn follows_def_with_dummy_body(self) -> bool {
matches!(self, Follows::DummyDef)
}
}

impl Follows {
const fn is_any_def(self) -> bool {
matches!(self, Follows::Def | Follows::DummyDef)
Expand Down Expand Up @@ -814,8 +821,7 @@ impl<'a> BlankLinesChecker<'a> {
&& matches!(line.kind, LogicalLineKind::Function | LogicalLineKind::Decorator)
// Allow groups of one-liners.
&& !(state.follows.is_any_def() && line.last_token != TokenKind::Colon)
// Allow a function/method to follow a function/method with a dummy body.
&& !matches!(state.follows, Follows::DummyDef)
&& !state.follows.follows_def_with_dummy_body()
&& matches!(state.class_status, Status::Inside(_))
// The class/parent method's docstring can directly precede the def.
// Allow following a decorator (if there is an error it will be triggered on the first decorator).
Expand Down Expand Up @@ -867,8 +873,7 @@ impl<'a> BlankLinesChecker<'a> {
&& !matches!(state.follows, Follows::Decorator)
// Allow groups of one-liners.
&& !(state.follows.is_any_def() && line.last_token != TokenKind::Colon)
// Allow a function/method to follow a function/method with a dummy body.
&& !matches!(state.follows, Follows::DummyDef)
&& !state.follows.follows_def_with_dummy_body()
// Only trigger on non-indented classes and functions (for example functions within an if are ignored)
&& line.indent_length == 0
// Only apply to functions or classes.
Expand Down Expand Up @@ -1035,8 +1040,7 @@ impl<'a> BlankLinesChecker<'a> {
&& prev_indent_length.is_some_and(|prev_indent_length| prev_indent_length >= line.indent_length)
// Allow groups of one-liners.
&& !(state.follows.is_any_def() && line.last_token != TokenKind::Colon)
// Allow a function/method to follow a function/method with a dummy body.
&& !matches!(state.follows, Follows::DummyDef)
&& !state.follows.follows_def_with_dummy_body()
// Blank lines in stub files are only used for grouping. Don't enforce blank lines.
&& !self.source_type.is_stub()
{
Expand Down

0 comments on commit 6751ef1

Please sign in to comment.