Skip to content

Conversation

@lidiyam
Copy link
Contributor

@lidiyam lidiyam commented Oct 13, 2017

Detect missing blank line after a class definition. (moved from starscream specific linter as suggested in https://github.com/Shopify/starscream/pull/21070)


def __class_def_check(self, node): # type: (astroid.ClassDef) -> None
"""Enforce a blank line after a class definition line."""
if isinstance(node, astroid.ClassDef):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary? Shouldn't visit_classdef only be called at a ClassDef line?

if isinstance(node, astroid.ClassDef):
class_def_line = node.lineno
for next_def in node.body:
if isinstance(next_def, astroid.FunctionDef):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, this would pass.

class SomeClass(object):
    FOO = 1
    def apply(self):
        pass

I believe the rule might be better expressed as: there must be at least one blank line before the first method of a class. Thoughts?

@lidiyam lidiyam merged commit 7992901 into master Oct 16, 2017
@pior pior mentioned this pull request Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants