Add noqa everywhere that it is easy to do so
Hacking attempts to standardize the style guide for OpenStack, but ultimately it is up to each project to accept and enforce each rule. Going with that, give each project finer grained control over enforcing each rule and support noqa where possible. This is a change of policy from only supporting noqa where a clear example was given needing it. This patch adds noqa support to every check that is easy to do so on. This attempts to preemptively support noqa, without going out of the way, as physical line checks don't automatically understand noqa like logical_line checks. Add noqa too: H701 H702 H232 H234 H235 H237 Change-Id: I0ddefdb84854ae61d2f15f20d6e8019f8c34f30a
This commit is contained in:
@@ -92,19 +92,23 @@ def check_i18n():
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def hacking_localization_strings(logical_line, tokens):
|
||||
def hacking_localization_strings(logical_line, tokens, noqa):
|
||||
r"""Check localization in line.
|
||||
|
||||
Okay: _("This is fine")
|
||||
Okay: _("This is also fine %s")
|
||||
Okay: _("So is this %s, %(foo)s") % {foo: 'foo'}
|
||||
H701: _('')
|
||||
Okay: _('') # noqa
|
||||
H702: _("Bob" + " foo")
|
||||
Okay: _("Bob" + " foo") # noqa
|
||||
H702: _("Bob %s" % foo)
|
||||
# H703 check is not quite right, disabled by removing colon
|
||||
H703 _("%s %s" % (foo, bar))
|
||||
"""
|
||||
# TODO(sdague) actually get these tests working
|
||||
if noqa:
|
||||
return
|
||||
gen = check_i18n()
|
||||
next(gen)
|
||||
try:
|
||||
|
||||
@@ -48,7 +48,7 @@ def hacking_python3x_except_compatible(logical_line, physical_line, noqa):
|
||||
|
||||
@core.skip_on_py3
|
||||
@core.flake8ext
|
||||
def hacking_python3x_octal_literals(logical_line, tokens):
|
||||
def hacking_python3x_octal_literals(logical_line, tokens, noqa):
|
||||
r"""Check for octal literals in Python 3.x compatible form.
|
||||
|
||||
As of Python 3.x, the construct "0755" has been removed.
|
||||
@@ -62,7 +62,10 @@ def hacking_python3x_octal_literals(logical_line, tokens):
|
||||
Okay: f(000)
|
||||
Okay: MiB = 1.0415
|
||||
H232: f(0755)
|
||||
Okay: f(0755) # noqa
|
||||
"""
|
||||
if noqa:
|
||||
return
|
||||
|
||||
for token_type, text, _, _, _ in tokens:
|
||||
if token_type == tokenize.NUMBER:
|
||||
@@ -100,15 +103,19 @@ def hacking_python3x_print_function(logical_line, physical_line, noqa):
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def hacking_no_assert_equals(logical_line, tokens):
|
||||
def hacking_no_assert_equals(logical_line, tokens, noqa):
|
||||
r"""assert(Not)Equals() is deprecated, use assert(Not)Equal instead.
|
||||
|
||||
Okay: self.assertEqual(0, 0)
|
||||
Okay: self.assertNotEqual(0, 1)
|
||||
H234: self.assertEquals(0, 0)
|
||||
H234: self.assertNotEquals(0, 1)
|
||||
Okay: self.assertEquals(0, 0) # noqa
|
||||
Okay: self.assertNotEquals(0, 1) # noqa
|
||||
"""
|
||||
|
||||
if noqa:
|
||||
return
|
||||
for token_type, text, start_index, _, _ in tokens:
|
||||
|
||||
if token_type == tokenize.NAME:
|
||||
@@ -118,13 +125,15 @@ def hacking_no_assert_equals(logical_line, tokens):
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def hacking_no_assert_underscore(logical_line, tokens):
|
||||
def hacking_no_assert_underscore(logical_line, tokens, noqa):
|
||||
r"""assert_() is deprecated, use assertTrue instead.
|
||||
|
||||
Okay: self.assertTrue(foo)
|
||||
H235: self.assert_(foo)
|
||||
Okay: self.assert_(foo) # noqa
|
||||
"""
|
||||
|
||||
if noqa:
|
||||
return
|
||||
for token_type, text, start_index, _, _ in tokens:
|
||||
|
||||
if token_type == tokenize.NAME and text == "assert_":
|
||||
@@ -173,7 +182,7 @@ removed_modules = [
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def hacking_no_removed_module(logical_line):
|
||||
def hacking_no_removed_module(logical_line, noqa):
|
||||
r"""Check for removed modules in Python 3.
|
||||
|
||||
Examples:
|
||||
@@ -182,9 +191,12 @@ def hacking_no_removed_module(logical_line):
|
||||
Okay: from os import (path as p)
|
||||
Okay: import os.path
|
||||
H237: import thread
|
||||
Okay: import thread # noqa
|
||||
H237: import commands
|
||||
H237: import md5 as std_md5
|
||||
"""
|
||||
if noqa:
|
||||
return
|
||||
line = core.import_normalize(logical_line.strip())
|
||||
if line and line.split()[0] == 'import':
|
||||
module_name = line.split()[1].split('.')[0]
|
||||
|
||||
Reference in New Issue
Block a user