Skip to content

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

Open

Description

@it-praktyk

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.

Activity

  1. asottile commented on Mar 22, 2020

    @asottile
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions