From 31f8cc52023aa2ca218473e55c6da3b1f81d94bc Mon Sep 17 00:00:00 2001 From: Rodrigo Mologni Date: Sat, 4 Dec 2021 12:42:23 -0300 Subject: [PATCH] feat: add 'flake8-max-doc-length' --- README.rst | 8 +++++--- pytest_flake8.py | 13 ++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 58bc0e0..a0d87ac 100644 --- a/README.rst +++ b/README.rst @@ -54,13 +54,15 @@ flake8. Configuring FLAKE8 options per project and file ----------------------------------------------- -Maximum line length can be configured for the whole project -by adding a ``flake8-max-line-length`` option to your ``setup.cfg`` -or ``tox.ini`` file like this:: +Maximum line length and maximum doc line length can be configured for the +whole project by adding a ``flake8-max-line-length`` option and +``flake8-max-doc-length`` to your ``setup.cfg`` or ``tox.ini`` file like +this:: # content of setup.cfg [tool:pytest] flake8-max-line-length = 99 + flake8-max-doc-length = 74 Note that the default will be what naturally comes with `flake8`_ (which it turn gets its default from `pycodestyle`_). diff --git a/pytest_flake8.py b/pytest_flake8.py index 1e45d8f..c9dcc5c 100644 --- a/pytest_flake8.py +++ b/pytest_flake8.py @@ -29,6 +29,9 @@ def pytest_addoption(parser): parser.addini( "flake8-max-line-length", help="maximum line length") + parser.addini( + "flake8-max-doc-length", + help="maximum doc line length") parser.addini( "flake8-max-complexity", help="McCabe complexity threshold") @@ -48,6 +51,7 @@ def pytest_configure(config): if config.option.flake8: config._flake8ignore = Ignorer(config.getini("flake8-ignore")) config._flake8maxlen = config.getini("flake8-max-line-length") + config._flake8maxdoclen = config.getini("flake8-max-doc-length") config._flake8maxcomplexity = config.getini("flake8-max-complexity") config._flake8showshource = config.getini("flake8-show-source") config._flake8statistics = config.getini("flake8-statistics") @@ -67,6 +71,7 @@ def pytest_collect_file(path, parent): item = Flake8Item.from_parent(parent, fspath=path) item.flake8ignore = flake8ignore item.maxlength = config._flake8maxlen + item.maxdoclength = config._flake8maxdoclen item.maxcomplexity = config._flake8maxcomplexity item.showshource = config._flake8showshource item.statistics = config._flake8statistics @@ -77,6 +82,7 @@ def pytest_collect_file(path, parent): parent, flake8ignore=flake8ignore, maxlength=config._flake8maxlen, + maxdoclength=config._flake8maxdoclen, maxcomplexity=config._flake8maxcomplexity, showshource=config._flake8showshource, statistics=config._flake8statistics) @@ -95,12 +101,14 @@ class Flake8Error(Exception): class Flake8Item(pytest.Item, pytest.File): def __init__(self, fspath, parent, flake8ignore=None, maxlength=None, + maxdoclength=None, maxcomplexity=None, showshource=None, statistics=None): super(Flake8Item, self).__init__(fspath, parent) self._nodeid += "::FLAKE8" self.add_marker("flake8") self.flake8ignore = flake8ignore self.maxlength = maxlength + self.maxdoclength = maxdoclength self.maxcomplexity = maxcomplexity self.showshource = showshource self.statistics = statistics @@ -122,6 +130,7 @@ def runtest(self): self.fspath, self.flake8ignore, self.maxlength, + self.maxdoclength, self.maxcomplexity, self.showshource, self.statistics) @@ -179,12 +188,14 @@ def __call__(self, path): return l -def check_file(path, flake8ignore, maxlength, maxcomplexity, +def check_file(path, flake8ignore, maxlength, maxdoclenght, maxcomplexity, showshource, statistics): """Run flake8 over a single file, and return the number of failures.""" args = [] if maxlength: args += ['--max-line-length', maxlength] + if maxdoclenght: + args += ['--max-doc-length', maxdoclenght] if maxcomplexity: args += ['--max-complexity', maxcomplexity] if showshource: