mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-06 21:16:54 +00:00
Merge branch 'disable-noqa-list' into 'master'
Allow disable-noqa to take a comma-separated list Closes #667 See merge request pycqa/flake8!435
This commit is contained in:
commit
eb2b2c93a0
5 changed files with 40 additions and 4 deletions
|
|
@ -64,6 +64,11 @@ All options available as of Flake8 3.1.0::
|
|||
E,F,W,C90)
|
||||
--disable-noqa Disable the effect of "# noqa". This will report
|
||||
errors on lines with "# noqa" at the end.
|
||||
May be a bare flag, a boolean value, or a
|
||||
comma-separated list of errors to disable "# noqa"
|
||||
for.
|
||||
A bare flag or a boolean true will disable all
|
||||
"# noqa"s.
|
||||
--show-source Show the source generate each error or warning.
|
||||
--statistics Count errors and warnings.
|
||||
--enable-extensions=ENABLE_EXTENSIONS
|
||||
|
|
|
|||
|
|
@ -621,11 +621,16 @@ Options and their Descriptions
|
|||
file. This option allows you to see all the warnings, errors, etc.
|
||||
reported.
|
||||
|
||||
In addition to a bare flag, this option also accepts a boolean value
|
||||
or a comma-separated list of codes to disable ``# NOQA`` for.
|
||||
|
||||
Command-line example:
|
||||
|
||||
.. prompt:: bash
|
||||
|
||||
flake8 --disable-noqa dir/
|
||||
flake8 --disable-noqa=true dir/
|
||||
flake8 --disable-noqa=E432,E5,W dir/
|
||||
|
||||
This **can** be specified in config files.
|
||||
|
||||
|
|
@ -635,6 +640,10 @@ Options and their Descriptions
|
|||
|
||||
disable_noqa = True
|
||||
disable-noqa = True
|
||||
disable_noqa =
|
||||
E432,
|
||||
E5,
|
||||
W
|
||||
|
||||
|
||||
.. option:: --show-source
|
||||
|
|
|
|||
|
|
@ -183,6 +183,21 @@ class Application(object):
|
|||
self.option_manager, config_finder, argv,
|
||||
)
|
||||
|
||||
# NOTE(plinss): post-process disable-noqa
|
||||
# allow bool or comma_separated_list
|
||||
if self.options.disable_noqa is None:
|
||||
# NOTE(plinss): option is present without value, treat as flag
|
||||
self.options.disable_noqa = True
|
||||
elif isinstance(self.options.disable_noqa, utils.string_types):
|
||||
if self.options.disable_noqa.lower() == "true":
|
||||
self.options.disable_noqa = True
|
||||
elif self.options.disable_noqa.lower() == "false":
|
||||
self.options.disable_noqa = False
|
||||
else:
|
||||
self.options.disable_noqa = utils.parse_comma_separated_list(
|
||||
self.options.disable_noqa
|
||||
)
|
||||
|
||||
self.running_against_diff = self.options.diff
|
||||
if self.running_against_diff:
|
||||
self.parsed_diff = utils.parse_unified_diff()
|
||||
|
|
|
|||
|
|
@ -269,7 +269,8 @@ def register_default_options(option_manager):
|
|||
"--disable-noqa",
|
||||
default=False,
|
||||
parse_from_config=True,
|
||||
action="store_true",
|
||||
action="store",
|
||||
nargs="?",
|
||||
help='Disable the effect of "# noqa". This will report errors on '
|
||||
'lines with "# noqa" at the end.',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ class Violation(_Violation):
|
|||
"""Class representing a violation reported by Flake8."""
|
||||
|
||||
def is_inline_ignored(self, disable_noqa):
|
||||
# type: (bool) -> bool
|
||||
# type: (Union[bool, List[str]]) -> bool
|
||||
"""Determine if a comment has been added to ignore this line.
|
||||
|
||||
:param bool disable_noqa:
|
||||
:param Uniol[bool, List[str]] disable_noqa:
|
||||
Whether or not users have provided ``--disable-noqa``.
|
||||
:returns:
|
||||
True if error is ignored in-line, False otherwise.
|
||||
|
|
@ -76,7 +76,13 @@ class Violation(_Violation):
|
|||
"""
|
||||
physical_line = self.physical_line
|
||||
# TODO(sigmavirus24): Determine how to handle stdin with linecache
|
||||
if disable_noqa:
|
||||
if (disable_noqa is True) or (
|
||||
isinstance(disable_noqa, list)
|
||||
and (
|
||||
(self.code in disable_noqa)
|
||||
or (self.code.startswith(tuple(disable_noqa)))
|
||||
)
|
||||
):
|
||||
return False
|
||||
|
||||
if physical_line is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue