summaryrefslogtreecommitdiff
path: root/src/flake8/defaults.py
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-07-26 19:41:41 -0500
committerIan Cordasco <graffatcolmingov@gmail.com>2016-07-26 19:45:05 -0500
commite51fc5458b81b6c56c359c79b13ce88b70e476ec (patch)
treefc869436089258d822661fa22e32a6c86b8d41e7 /src/flake8/defaults.py
parent6eca38f2f2a15765aecef010f878aa17fdbe1db7 (diff)
downloadflake8-e51fc5458b81b6c56c359c79b13ce88b70e476ec.tar.gz
Fix handling of logical lines with noqa
When attempting to centralize all inline NoQA handling in the StyleGuide we inadvertently broke plugins relying on it in combination with checker state. For example, the check for E402 relies both on NoQA and the state to determine if it has seen a non-import line. Placing NoQA on the sole line that is not an import is more elegant than placing it on each of the following import lines. Closes #186
Diffstat (limited to 'src/flake8/defaults.py')
-rw-r--r--src/flake8/defaults.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/flake8/defaults.py b/src/flake8/defaults.py
index ede2946..73cadf1 100644
--- a/src/flake8/defaults.py
+++ b/src/flake8/defaults.py
@@ -1,4 +1,5 @@
"""Constants that define defaults."""
+import re
EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg'
IGNORE = 'E121,E123,E126,E226,E24,E704,W503,W504'
@@ -15,3 +16,19 @@ STATISTIC_NAMES = (
'physical lines',
'tokens',
)
+
+NOQA_INLINE_REGEXP = re.compile(
+ # We're looking for items that look like this:
+ # ``# noqa``
+ # ``# noqa: E123``
+ # ``# noqa: E123,W451,F921``
+ # ``# NoQA: E123,W451,F921``
+ # ``# NOQA: E123,W451,F921``
+ # We do not care about the ``: `` that follows ``noqa``
+ # We do not care about the casing of ``noqa``
+ # We want a comma-separated list of errors
+ '# noqa(?:: (?P<codes>[A-Z0-9,]+))?',
+ re.IGNORECASE
+)
+
+NOQA_FILE = re.compile(r'\s*# flake8[:=]\s*noqa', re.I)