Catch .format() use in log string interpoliation check

This adds checking for using .format() instead of % when looking for
cases of preformatting log strings.

Change-Id: Ia12f898ca3d206c9da0e5057c7223e124ee2548c
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2020-10-13 12:05:00 -05:00
parent 31e9c8751e
commit f82f995d02
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
2 changed files with 2 additions and 1 deletions

View File

@ -55,5 +55,5 @@ def hacking_delayed_string_interpolation(logical_line, noqa):
# There are some cases where string formatting of the arguments are
# needed, so don't include those when checking.
line = re.sub(r",.*", '', line)
if '%' in line:
if '%' in line or '.format' in line:
yield 0, msg

View File

@ -25,6 +25,7 @@ class OthersTestCase(tests.TestCase):
@ddt.data(
(1, 'LOG.debug("Test %s" % foo)', None),
(0, 'LOG.info("Test %s", foo)', None),
(1, 'LOG.info("Test {}".format(foo))', None),
(0, 'LOG.error("Test %s" % foo)', '# noqa'),
(1, 'LOG.debug("Test %s" % "foo")', None),
(0, 'LOG.debug("Test %s", "foo")', None),