From 3b1316a9b2663b60213a9a53de9381185ebbf33c Mon Sep 17 00:00:00 2001 From: srisankethu Date: Thu, 10 Nov 2016 21:49:47 +0530 Subject: [PATCH] bears/python: Add PyFlakesBear Closes https://github.com/coala/coala-bears/issues/825 --- bears/python/PyFlakesBear.py | 29 +++++++++++++++++++++++++++++ requirements.txt | 2 +- tests/python/PyFlakesBearTest.py | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 bears/python/PyFlakesBear.py create mode 100644 tests/python/PyFlakesBearTest.py diff --git a/bears/python/PyFlakesBear.py b/bears/python/PyFlakesBear.py new file mode 100644 index 0000000000..8110a0c9c7 --- /dev/null +++ b/bears/python/PyFlakesBear.py @@ -0,0 +1,29 @@ +from coalib.bearlib.abstractions.Linter import linter +from coalib.bears.requirements.PipRequirement import PipRequirement +from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY + + +@linter(executable='pyflakes', + output_format='regex', + output_regex=r'(?P.*):(?P.*):\s*' + r'(?P)\s(?P.*)', + severity_map={ + '': RESULT_SEVERITY.INFO + }) +class PyFlakesBear: + """ + Checks Python files for logistic errors using ``pyflakes``. + + See https://github.com/PyCQA/pyflakes for more info. + """ + LANGUAGES = {"Python", "Python 3"} + REQUIREMENTS = {PipRequirement('pyflakes', '1.2.*')} + AUTHORS = {'The coala developers'} + AUTHORS_EMAILS = {'coala-devel@googlegroups.com'} + LICENSE = 'AGPL-3.0' + ASCIINEMA_URL = 'https://asciinema.org/a/92503' + CAN_DETECT = {'Syntax', 'Unused imports', 'Undefined Element'} + + @staticmethod + def create_arguments(filename, file, config_file): + return filename, diff --git a/requirements.txt b/requirements.txt index a643786b31..3bb545ec41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,6 +28,6 @@ pyyaml==3.* vulture==0.10.* bandit==1.1.* nbformat>=4.* -pyflakes==1.2.* # Although we don't need this directly, solves a dep conflict +pyflakes==1.2.* scspell3k==2.* mypy-lang==0.4.* diff --git a/tests/python/PyFlakesBearTest.py b/tests/python/PyFlakesBearTest.py new file mode 100644 index 0000000000..0f1220223d --- /dev/null +++ b/tests/python/PyFlakesBearTest.py @@ -0,0 +1,15 @@ +from bears.python.PyFlakesBear import PyFlakesBear +from tests.LocalBearTestHelper import verify_local_bear + +good_file = """ +print("Hi") +""" + +bad_file = """ +import os +print("Hi") +""" + +PyFlakesBear = verify_local_bear(PyFlakesBear, + valid_files=(good_file,), + invalid_files=(bad_file,))