Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for blank line after a class definition #86

Merged
merged 3 commits into from Oct 16, 2017
Merged

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):
Copy link
Member

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):
Copy link
Member

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.

None yet

3 participants