mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-02 03:46:53 +00:00
Create and enable the Pyflakes extension
This commit is contained in:
parent
701ec32e3f
commit
212364d89c
2 changed files with 51 additions and 1 deletions
47
flake8/_pyflakes.py
Normal file
47
flake8/_pyflakes.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pyflakes
|
||||
import pyflakes.checker
|
||||
|
||||
|
||||
def patch_pyflakes():
|
||||
"""Add error codes to Pyflakes messages."""
|
||||
codes = dict([line.split()[::-1] for line in (
|
||||
'F401 UnusedImport',
|
||||
'F402 ImportShadowedByLoopVar',
|
||||
'F403 ImportStarUsed',
|
||||
'F404 LateFutureImport',
|
||||
'F810 Redefined', # XXX Obsolete?
|
||||
'F811 RedefinedWhileUnused',
|
||||
'F812 RedefinedInListComp',
|
||||
'F821 UndefinedName',
|
||||
'F822 UndefinedExport',
|
||||
'F823 UndefinedLocal',
|
||||
'F831 DuplicateArgument',
|
||||
'F841 UnusedVariable',
|
||||
)])
|
||||
|
||||
for name, obj in vars(pyflakes.messages).items():
|
||||
if name[0].isupper() and obj.message:
|
||||
obj.flint_msg = '%s %s' % (codes.get(name, 'F999'), obj.message)
|
||||
patch_pyflakes()
|
||||
|
||||
|
||||
class FlakesChecker(pyflakes.checker.Checker):
|
||||
"""Subclass the Pyflakes checker to conform with the flint API."""
|
||||
name = 'pyflakes'
|
||||
version = pyflakes.__version__
|
||||
|
||||
@classmethod
|
||||
def add_options(cls, parser):
|
||||
parser.add_option('--builtins',
|
||||
help="define more built-ins, comma separated")
|
||||
parser.config_options.append('builtins')
|
||||
|
||||
@classmethod
|
||||
def parse_options(cls, options):
|
||||
if options.builtins:
|
||||
cls.builtIns = cls.builtIns.union(options.builtins.split(','))
|
||||
|
||||
def run(self):
|
||||
for m in self.messages:
|
||||
yield m.lineno, 0, (m.flint_msg % m.message_args), m.__class__
|
||||
5
setup.py
5
setup.py
|
|
@ -33,7 +33,10 @@ setup(
|
|||
],
|
||||
entry_points={
|
||||
'distutils.commands': ['flake8 = flake8.main:Flake8Command'],
|
||||
'console_scripts': ['flake8 = flake8.main:main']
|
||||
'console_scripts': ['flake8 = flake8.main:main'],
|
||||
'flake8.extension': [
|
||||
'F = flake8._pyflakes:FlakesChecker',
|
||||
],
|
||||
},
|
||||
tests_require=['nose'],
|
||||
test_suite='nose.collector',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue