Skip to content

Commit

Permalink
bears/python: Add PyFlakesBear
Browse files Browse the repository at this point in the history
Closes coala#825
  • Loading branch information
srisankethu committed Nov 26, 2016
1 parent 53d0d9d commit 945a02b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bears/python/PyFlakesBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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',
use_stderr=True,
output_format='regex',
output_regex=r'(?P<filename>.*):(?P<line>\d+):'
r'[(?P<column>\d*):|?]*(?P<severity>)\s(?P<message>.*)\n',
severity_map={
'': RESULT_SEVERITY.INFO
})
class PyFlakesBear:
"""
Checks Python files for 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 = {'[email protected]'}
LICENSE = 'AGPL-3.0'
ASCIINEMA_URL = 'https://asciinema.org/a/92503'
CAN_DETECT = {'Syntax', 'Unused Code', 'Undefined Element'}

@staticmethod
def create_arguments(filename, file, config_file):
return filename,
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pyyaml~=3.12
vulture~=0.10
bandit~=1.2
nbformat>=4.1
pyflakes~=1.2.0
scspell3k~=2.0
mypy-lang~=0.4
rstcheck~=2.2
Expand Down
15 changes: 15 additions & 0 deletions tests/python/PyFlakesBearTest.py
Original file line number Diff line number Diff line change
@@ -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,))

0 comments on commit 945a02b

Please sign in to comment.