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

Advanced usage question: How to call the pycodestyle with custom rule in the external file #917

Open
it-praktyk opened this issue Mar 22, 2020 · 1 comment

Comments

@it-praktyk
Copy link

I try to write a wrapper to call the pycodestyle with the rule in the wrapper file.

My rule/wrapper looks like.

import pycodestyle


def _main(**kwargs)


    @pycodestyle.register_check
    def image_lines(logical_line):
        r"""Find the line starting from the
        - FROM
        - image:
        directives.

        I801: def a():\n    pass\na()
        I802: def b():\n    pass\na()
        """ #noqa

        if logical_line.startswith('FROM'):
            yield 0, "I801 found the FROM directive"
        elif logical_line.startswith('image:'):
            yield 0, "I802 found the image directive"


    style = pycodestyle.StyleGuide(filename=['Dockerfile', 'docker-compose.yml'], select=['I801', 'I802'])

if __name__ == '__main__':
    _main()

Can you help me? Thank you.

@asottile
Copy link
Member

fwiw, it's probably easier to use flake8 as a plugin system rather than pycodestyle

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

No branches or pull requests

2 participants