diff --git a/setup.cfg b/setup.cfg index 54e479c5c..b24583f80 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,5 +7,35 @@ markers = linter online +[flake8] +exclude = + conf.py, + .venv, +ignore = + # ignore presence of unnecessary generators + C402, + # ignore presence of unnecessary literals + C405, + # ignore presence of unnecessary comprehensions + C407, + # ignore presence of unnecessary tuple/list/dict + C408, + # ignore documentation related warnings + D, + # ignore presence of unused imports + F401, + # ignore presence of unused variables + F841, + # ignore import order related warnings + I, + # ignore presence of upper case in function names + N802, + # ignore line breaks after binary operator (new rule added in 2018) + W504, +max-line-length = 200 +# due to complexity not being enforced before, 26 is the minimum for not +# throwing errors. +max-complexity = 26 + [coverage:run] source = rosdep2 diff --git a/test/test_flake8.py b/test/test_flake8.py index 10f3340a4..ebb90fc6c 100644 --- a/test/test_flake8.py +++ b/test/test_flake8.py @@ -15,49 +15,22 @@ from __future__ import print_function import os +import subprocess import sys -from flake8.api.legacy import get_style_guide import pytest @pytest.mark.flake8 @pytest.mark.linter def test_flake8(): - style_guide = get_style_guide( - exclude=['conf.py'], - ignore=[ - 'C402', # ignore presence of unnecessary generators - 'C405', # ignore presence of unnecessary literals - 'C407', # ignore presence of unnecessary comprehensions - 'C408', # ignore presence of unnecessary tuple/list/dict - 'D', # ignore documentation related warnings - 'F401', # ignore presence of unused imports - 'F841', # ignore presence of unused variables - 'I', # ignore import order related warnings - 'N802', # ignore presence of upper case in function names - 'W504', # ignore line breaks after binary operator (new rule added in 2018) - ], - max_line_length=200, - max_complexity=10, - show_source=True, + # flake8 doesn't have a stable public API as of ver 6.1.0. + # See: https://flake8.pycqa.org/en/latest/user/python-api.html + # Calling through subprocess is the most stable way to run it. + + # We still need to support Python 2.7, so we can't use run() + ret_code = subprocess.call( + [sys.executable, "-m", "flake8"], + cwd=os.path.dirname(os.path.dirname(__file__)), ) - - stdout = sys.stdout - sys.stdout = sys.stderr - # implicitly calls report_errors() - report = style_guide.check_files([ - os.path.dirname(os.path.dirname(__file__)), - ]) - sys.stdout = stdout - - if report.total_errors: - # output summary with per-category counts - print() - report._application.formatter.show_statistics(report._stats) - print( - 'flake8 reported {report.total_errors} errors' - .format(**locals()), file=sys.stderr) - - assert not report.total_errors, \ - 'flake8 reported {report.total_errors} errors'.format(**locals()) + assert 0 == ret_code, "flake8 found violations"