Skip to content

Commit

Permalink
Merge pull request #100 from carlio/feature/rename-pyflakes-codes
Browse files Browse the repository at this point in the history
Rename pyflakes codes
  • Loading branch information
carlio committed Jan 30, 2015
2 parents a7f1039 + 4358368 commit c2c40d7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
4 changes: 0 additions & 4 deletions prospector/profiles/profiles/no_doc_warnings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ pylint:
- empty-docstring
- missing-docstring

pyflakes:
disable:
- FL0007

frosted:
disable:
- E401
Expand Down
4 changes: 2 additions & 2 deletions prospector/profiles/profiles/strictness_low.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pylint:

pyflakes:
disable:
- FL0001
- FL0013
- F401
- F841

frosted:
disable:
Expand Down
4 changes: 2 additions & 2 deletions prospector/profiles/profiles/strictness_medium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ mccabe:

pyflakes:
disable:
- FL0005
- FL0011
- F403
- F810

frosted:
disable:
Expand Down
9 changes: 9 additions & 0 deletions prospector/tools/profile_validator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from prospector.message import Location, Message
from prospector.profiles import AUTO_LOADED_PROFILES
from prospector.tools import ToolBase
from prospector.tools import pyflakes


CONFIG_SETTING_SHOULD_BE_LIST = 'should-be-list'
Expand All @@ -13,6 +14,7 @@
CONFIG_INVALID_VALUE = 'invalid-value'
CONFIG_INVALID_REGEXP = 'invalid-regexp'
CONFIG_DEPRECATED_SETTING = 'deprecated'
CONFIG_DEPRECATED_CODE = 'deprecated-tool-code'


class ProfileValidationTool(ToolBase):
Expand Down Expand Up @@ -104,6 +106,13 @@ def add_message(code, message, setting):
if key not in ProfileValidationTool.ALL_SETTINGS and key not in self.tool_names():
add_message(CONFIG_UNKNOWN_SETTING, '"%s" is not a valid prospector setting' % key, key)

if 'pyflakes' in parsed:
for code in parsed['pyflakes'].get('enable', []) + parsed['pyflakes'].get('disable', []):
if code in pyflakes.LEGACY_CODE_MAP:
add_message(CONFIG_DEPRECATED_CODE,
'Pyflakes code %s was renamed to %s' % (code, pyflakes.LEGACY_CODE_MAP[code]),
'pyflakes')

return messages

def run(self, found_files):
Expand Down
53 changes: 36 additions & 17 deletions prospector/tools/pyflakes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,39 @@
)


# Prospector uses the same pyflakes codes as flake8 defines,
# see http://flake8.readthedocs.org/en/latest/warnings.html
# and https://bitbucket.org/tarek/flake8/src/a209fb69350c572c9b2d7b4b09c7657be153be5e/flake8/_pyflakes.py
_MESSAGE_CODES = {
'UnusedImport': 'FL0001',
'RedefinedWhileUnused': 'FL0002',
'RedefinedInListComp': 'FL0003',
'ImportShadowedByLoopVar': 'FL0004',
'ImportStarUsed': 'FL0005',
'UndefinedName': 'FL0006',
'DoctestSyntaxError': 'FL0007',
'UndefinedExport': 'FL0008',
'UndefinedLocal': 'FL0009',
'DuplicateArgument': 'FL0010',
'Redefined': 'FL0011',
'LateFutureImport': 'FL0012',
'UnusedVariable': 'FL0013',
'UnusedImport': 'F401',
'ImportShadowedByLoopVar': 'F402',
'ImportStarUsed': 'F403',
'LateFutureImport': 'F404',
'Redefined': 'F810',
'RedefinedWhileUnused': 'F811',
'RedefinedInListComp': 'F812',
'UndefinedName': 'F821',
'UndefinedExport': 'F822',
'UndefinedLocal': 'F823',
'DuplicateArgument': 'F831',
'UnusedVariable': 'F841',
}

# The old prospector codes were deprecated in favour of using the codes
# defined by flake8. This maps the old codes to the new codes.
LEGACY_CODE_MAP = {
'FL0001': 'F401',
'FL0002': 'F811',
'FL0003': 'F812',
'FL0004': 'F402',
'FL0005': 'F403',
'FL0006': 'F821',
'FL0008': 'F822',
'FL0009': 'F823',
'FL0010': 'F831',
'FL0011': 'F810',
'FL0012': 'F404',
'FL0013': 'F841',
}


Expand All @@ -44,7 +63,7 @@ def record_message(
code=None,
message=None):

code = code or 'FL0000'
code = code or 'F999'
if code in self.ignore:
return

Expand All @@ -66,7 +85,7 @@ def record_message(
def unexpectedError(self, filename, msg): # noqa
self.record_message(
filename=filename,
code='FL9997',
code='F999',
message=msg,
)

Expand All @@ -76,12 +95,12 @@ def syntaxError(self, filename, msg, lineno, offset, text): # noqa
filename=filename,
line=lineno,
character=offset,
code='FL9998',
code='F999',
message=msg,
)

def flake(self, message):
code = _MESSAGE_CODES.get(message.__class__.__name__, 'FL9999')
code = _MESSAGE_CODES.get(message.__class__.__name__, 'F999')

self.record_message(
filename=message.filename,
Expand Down

0 comments on commit c2c40d7

Please sign in to comment.