Sylvain Thénault avatar Sylvain Thénault committed 51ee3f8

built-in checkers use [01-50] base message ids (closes #68057)

Comments (0)

Files changed (17)

 ====================
 
 	--
-	
+    * ids of logging and string_format checkers have been changed:
+      logging: 65 -> 12, string_format: 99 -> 13
+      Also add documentation to say that ids of range 1-50 shall be reserved
+      to pylint internal checkers
+
     * #69993: Additional string format checks for logging module:
       check for missing arguments, too many arguments, or invalid string
       formats in the logging checker module. Contributed by Daniel Arena
-	
+
     * #69220: add column offset to the reports. If you've a custom reporter,
       this change may break it has now location gain a new item giving the
       column offset.

checkers/__init__.py

 09: design_analysis
 10: newstyle
 11: typecheck
+12: logging
+13: string_format
+14-50: not yet used: reserved for future internal checkers.
+51-99: perhaps used: reserved for external checkers
 
 The raw_metrics checker has no number associated since it doesn't emit any
 messages nor reports. XXX not true, emit a 07 report !
+
 """
 
 import tokenize

checkers/logging.py

 
 
 MSGS = {
-    'W6501': ('Specify string format arguments as logging function parameters',
+    'W1201': ('Specify string format arguments as logging function parameters',
              'Used when a logging statement has a call form of '
              '"logging.<logging method>(format_string % (format_args...))". '
              'Such calls should leave string interpolation to the logging '
              'interpolation in those cases in which no message will be '
              'logged. For more, see '
              'http://www.python.org/dev/peps/pep-0282/.'),
-    'E6500': ('Unsupported logging format character %r (%#02x) at index %d',
+    'E1200': ('Unsupported logging format character %r (%#02x) at index %d',
               'Used when an unsupported format character is used in a logging\
               statement format string.'),
-    'E6501': ('Logging format string ends in middle of conversion specifier',
+    'E1201': ('Logging format string ends in middle of conversion specifier',
               'Used when a logging statement format string terminates before\
               the end of a conversion specifier.'),
-    'E6505': ('Too many arguments for logging format string',
+    'E1205': ('Too many arguments for logging format string',
               'Used when a logging format string is given too few arguments.'),
-    'E6506': ('Not enough arguments for logging format string',
+    'E1206': ('Not enough arguments for logging format string',
               'Used when a logging format string is given too many arguments'),
     }
 
             # scope of this checker.
             return
         if isinstance(node.args[0], astng.BinOp) and node.args[0].op == '%':
-            self.add_message('W6501', node=node)
+            self.add_message('W1201', node=node)
         elif isinstance(node.args[0], astng.Const):
             self._check_format_string(node, 0)
 
             # the scope of this checker.
             return
         if isinstance(node.args[1], astng.BinOp) and node.args[1].op == '%':
-            self.add_message('W6501', node=node)
+            self.add_message('W1201', node=node)
         elif isinstance(node.args[1], astng.Const):
             self._check_format_string(node, 1)
 
                     return
             except utils.UnsupportedFormatCharacter, e:
                 c = format_string[e.index]
-                self.add_message('E6500', node=node, args=(c, ord(c), e.index))
+                self.add_message('E1200', node=node, args=(c, ord(c), e.index))
                 return
             except utils.IncompleteFormatString:
-                self.add_message('E6501', node=node)
+                self.add_message('E1201', node=node)
                 return
         if num_args > required_num_args:
-            self.add_message('E6505', node=node)
+            self.add_message('E1205', node=node)
         elif num_args < required_num_args:
-            self.add_message('E6506', node=node)
+            self.add_message('E1206', node=node)
 
     def _count_supplied_tokens(self, args):
         """Counts the number of tokens in an args list.

checkers/string_format.py

 
 
 MSGS = {
-    'E9900': ("Unsupported format character %r (%#02x) at index %d",
+    'E1300': ("Unsupported format character %r (%#02x) at index %d",
               "Used when a unsupported format character is used in a format\
               string."),
-    'E9901': ("Format string ends in middle of conversion specifier",
+    'E1301': ("Format string ends in middle of conversion specifier",
               "Used when a format string terminates before the end of a \
               conversion specifier."),
-    'E9902': ("Mixing named and unnamed conversion specifiers in format string",
+    'E1302': ("Mixing named and unnamed conversion specifiers in format string",
               "Used when a format string contains both named (e.g. '%(foo)d') \
               and unnamed (e.g. '%d') conversion specifiers.  This is also \
               used when a named conversion specifier contains * for the \
               minimum field width and/or precision."),
-    'E9903': ("Expected mapping for format string, not %s",
+    'E1303': ("Expected mapping for format string, not %s",
               "Used when a format string that uses named conversion specifiers \
               is used with an argument that is not a mapping."),
-    'W9900': ("Format string dictionary key should be a string, not %s",
+    'W1300': ("Format string dictionary key should be a string, not %s",
               "Used when a format string that uses named conversion specifiers \
               is used with a dictionary whose keys are not all strings."),
-    'W9901': ("Unused key %r in format string dictionary",
+    'W1301': ("Unused key %r in format string dictionary",
               "Used when a format string that uses named conversion specifiers \
               is used with a dictionary that conWtains keys not required by the \
               format string."),
-    'E9904': ("Missing key %r in format string dictionary",
+    'E1304': ("Missing key %r in format string dictionary",
               "Used when a format string that uses named conversion specifiers \
               is used with a dictionary that doesn't contain all the keys \
               required by the format string."),
-    'E9905': ("Too many arguments for format string",
+    'E1305': ("Too many arguments for format string",
               "Used when a format string that uses unnamed conversion \
               specifiers is given too few arguments."),
-    'E9906': ("Not enough arguments for format string",
+    'E1306': ("Not enough arguments for format string",
               "Used when a format string that uses unnamed conversion \
               specifiers is given too many arguments"),
     }
                 utils.parse_format_string(format_string)
         except utils.UnsupportedFormatCharacter, e:
             c = format_string[e.index]
-            self.add_message('E9900', node=node, args=(c, ord(c), e.index))
+            self.add_message('E1300', node=node, args=(c, ord(c), e.index))
             return
         except utils.IncompleteFormatString:
-            self.add_message('E9901', node=node)
+            self.add_message('E1301', node=node)
             return
         if required_keys and required_num_args:
             # The format string uses both named and unnamed format
             # specifiers.
-            self.add_message('E9902', node=node)
+            self.add_message('E1302', node=node)
         elif required_keys:
             # The format string uses only named format specifiers.
             # Check that the RHS of the % operator is a mapping object
                         if isinstance(key, basestring):
                             keys.add(key)
                         else:
-                            self.add_message('W9900', node=node, args=key)
+                            self.add_message('W1300', node=node, args=key)
                     else:
                         # One of the keys was something other than a
                         # constant.  Since we can't tell what it is,
                 if not unknown_keys:
                     for key in required_keys:
                         if key not in keys:
-                            self.add_message('E9904', node=node, args=key)
+                            self.add_message('E1304', node=node, args=key)
                 for key in keys:
                     if key not in required_keys:
-                        self.add_message('W9901', node=node, args=key)
+                        self.add_message('W1301', node=node, args=key)
             elif isinstance(args, OTHER_NODES + (astng.Tuple,)):
                 type_name = type(args).__name__
-                self.add_message('E9903', node=node, args=type_name)
+                self.add_message('E1303', node=node, args=type_name)
             # else:
                 # The RHS of the format specifier is a name or
                 # expression.  It may be a mapping object, so
                 num_args = None
             if num_args is not None:
                 if num_args > required_num_args:
-                    self.add_message('E9905', node=node)
+                    self.add_message('E1305', node=node)
                 elif num_args < required_num_args:
-                    self.add_message('E9906', node=node)
+                    self.add_message('E1306', node=node)
 
 
 def register(linter):
 
 Messages
 ~~~~~~~~
-:W6501: *Specify string format arguments as logging function parameters*
+:W1201: *Specify string format arguments as logging function parameters*
   Used when a logging statement has a call form of "logging.<logging
   method>(format_string % (format_args...))". Such calls should leave string
   interpolation to the logging method itself and be written "logging.<logging
   incurring the cost of the interpolation in those cases in which no message
   will be logged. For more, see http://www.python.org/dev/peps/pep-0282/.
 
+:E1200: *Unsupported logging format character %r (%#02x) at index %d*
+  Used when an unsupported format character is used in a logging statement 
+  format string.
+
+:E1201: *'Logging format string ends in middle of conversion specifier*
+  Used when a logging statement format string terminates before the end of a
+  conversion specifier.
+
+:E1205: *Too many arguments for logging format string*
+  Used when a logging format string is given too few arguments.
+
+:E1206: *Not enough arguments for logging format string*
+  Used when a logging format string is given too many arguments.
 
 similarities checker
 --------------------
 
 Messages
 ~~~~~~~~
-:E9900: *Unsupported format character %r (%#02x) at index %d*
+:E1300: *Unsupported format character %r (%#02x) at index %d*
   Used when a unsupported format character is used in a format string.
-:E9901: *Format string ends in middle of conversion specifier*
+:E1301: *Format string ends in middle of conversion specifier*
   Used when a format string terminates before the end of a conversion specifier.
-:E9902: *Mixing named and unnamed conversion specifiers in format string*
+:E1302: *Mixing named and unnamed conversion specifiers in format string*
   Used when a format string contains both named (e.g. '%(foo)d') and unnamed
   (e.g. '%d') conversion specifiers. This is also used when a named conversion
   specifier contains * for the minimum field width and/or precision.
-:E9903: *Expected mapping for format string, not %s*
+:E1303: *Expected mapping for format string, not %s*
   Used when a format string that uses named conversion specifiers is used with
   an argument that is not a mapping.
-:E9904: *Missing key %r in format string dictionary*
+:E1304: *Missing key %r in format string dictionary*
   Used when a format string that uses named conversion specifiers is used with a
   dictionary that doesn't contain all the keys required by the format string.
-:E9905: *Too many arguments for format string*
+:E1305: *Too many arguments for format string*
   Used when a format string that uses unnamed conversion specifiers is given too
   few arguments.
-:E9906: *Not enough arguments for format string*
+:E1306: *Not enough arguments for format string*
   Used when a format string that uses unnamed conversion specifiers is given too
   many arguments
-:W9900: *Format string dictionary key should be a string, not %s*
+:W1300: *Format string dictionary key should be a string, not %s*
   Used when a format string that uses named conversion specifiers is used with a
   dictionary whose keys are not all strings.
-:W9901: *Unused key %r in format string dictionary*
+:W1301: *Unused key %r in format string dictionary*
   Used when a format string that uses named conversion specifiers is used with a
   dictionary that conWtains keys not required by the format string.
 
   This is a particular case of W0104 with its own message so you can easily
   disable it if you're using those strings as documentation, instead of
   comments.
+:W0106: *Expression "%s" is assigned to nothing',*
+  Used when an expression that is not a function call is assigned to nothing. 
+  Probably something else was intended.
 :W0107: *Unnecessary pass statement*
   Used when a "pass" statement that can be avoided is encountered.)
 :W0108: *Lambda may not be necessary*

test/input/func_e12xx.py

+# pylint: disable=E1101
+"""Test checking of log format strings
+"""
+
+__revision__ = ''
+
+import logging
+
+def pprint():
+    """Test string format in logging statements.
+    """
+    # These should all emit lint errors:
+    logging.info(0, '') # 1205
+    logging.info('', '') # 1205
+    logging.info('%s%', '') # 1201
+    logging.info('%s%s', '') # 1206
+    logging.info('%s%a', '', '') # 1200
+    logging.info('%s%s', '', '', '') # 1205
+
+    # These should be okay:
+    logging.info(1)
+    logging.info(True)
+    logging.info('')
+    logging.info('%s%')
+    logging.info('%s', '')
+    logging.info('%s%%', '')
+    logging.info('%s%s', '', '')

test/input/func_e13xx.py

+"""test string format error
+"""
+
+__revision__ = 1
+
+PARG_1 = PARG_2 = PARG_3 = 1
+
+def pprint():
+    """Test string format
+    """
+    print "%s %s" % {'PARG_1': 1, 'PARG_2': 2} # E1306
+    print "%s" % (PARG_1, PARG_2) # E1305
+    print "%(PARG_1)d %d" % {'PARG_1': 1, 'PARG_2': 2} # E1302
+    print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1} # E1304
+    print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 'PARG_2':2, 'PARG_3':3}#W1301
+    print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 2:3} # W1300 E1304
+    print "%(PARG_1)d %(PARG_2)d" % (2, 3) # 1303
+    print "%(PARG_1)d %(PARG_2)d" % [2, 3] # 1303
+    print "%2z" % PARG_1
+    print "strange format %2" % PARG_2
+

test/input/func_e65xx.py

-# pylint: disable=E1101
-"""Test checking of log format strings
-"""
-
-__revision__ = ''
-
-import logging
-
-def pprint():
-    """Test string format in logging statements.
-    """
-    # These should all emit lint errors:
-    logging.info(0, '') # 6505
-    logging.info('', '') # 6505
-    logging.info('%s%', '') # 6501
-    logging.info('%s%s', '') # 6506
-    logging.info('%s%a', '', '') # 6500
-    logging.info('%s%s', '', '', '') # 6505
-
-    # These should be okay:
-    logging.info(1)
-    logging.info(True)
-    logging.info('')
-    logging.info('%s%')
-    logging.info('%s', '')
-    logging.info('%s%%', '')
-    logging.info('%s%s', '', '')

test/input/func_e99xx.py

-"""test string format error
-"""
-
-__revision__ = 1
-
-PARG_1 = PARG_2 = PARG_3 = 1
-
-def pprint():
-    """Test string format
-    """
-    print "%s %s" % {'PARG_1': 1, 'PARG_2': 2} # E9906
-    print "%s" % (PARG_1, PARG_2) # E9905
-    print "%(PARG_1)d %d" % {'PARG_1': 1, 'PARG_2': 2} # E9902
-    print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1} # E9904
-    print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 'PARG_2':2, 'PARG_3':3}#W9901
-    print "%(PARG_1)d %(PARG_2)d" % {'PARG_1': 1, 2:3} # W9900 E9904
-    print "%(PARG_1)d %(PARG_2)d" % (2, 3) # 9903
-    print "%(PARG_1)d %(PARG_2)d" % [2, 3] # 9903
-    print "%2z" % PARG_1
-    print "strange format %2" % PARG_2
-

test/input/func_w1201.py

+# pylint: disable=E1101
+"""test checking use of the logging module
+"""
+
+__revision__ = ''
+
+# Muck up the names in an effort to confuse...
+import logging as renamed_logging
+import os as logging
+
+# Statements that should be flagged:
+renamed_logging.warn('%s, %s' % (4, 5))
+renamed_logging.exception('%s' % 'Exceptional!')
+renamed_logging.log(renamed_logging.INFO, 'msg: %s' % 'Run!')
+
+# Statements that should not be flagged:
+renamed_logging.warn('%s, %s', 4, 5)
+renamed_logging.log(renamed_logging.INFO, 'msg: %s', 'Run!')
+renamed_logging.warn('%s' + ' the rest of a single string')
+logging.warn('%s, %s' % (4, 5))
+logging.log(logging.INFO, 'msg: %s' % 'Run!')

test/input/func_w6501.py

-# pylint: disable=E1101
-"""test checking use of the logging module
-"""
-
-__revision__ = ''
-
-# Muck up the names in an effort to confuse...
-import logging as renamed_logging
-import os as logging
-
-# Statements that should be flagged:
-renamed_logging.warn('%s, %s' % (4, 5))
-renamed_logging.exception('%s' % 'Exceptional!')
-renamed_logging.log(renamed_logging.INFO, 'msg: %s' % 'Run!')
-
-# Statements that should not be flagged:
-renamed_logging.warn('%s, %s', 4, 5)
-renamed_logging.log(renamed_logging.INFO, 'msg: %s', 'Run!')
-renamed_logging.warn('%s' + ' the rest of a single string')
-logging.warn('%s, %s' % (4, 5))
-logging.log(logging.INFO, 'msg: %s' % 'Run!')

test/messages/func_e12xx.txt

+E: 13:pprint: Too many arguments for logging format string
+E: 14:pprint: Too many arguments for logging format string
+E: 15:pprint: Logging format string ends in middle of conversion specifier
+E: 16:pprint: Not enough arguments for logging format string
+E: 17:pprint: Unsupported logging format character 'a' (0x61) at index 3
+E: 18:pprint: Too many arguments for logging format string

test/messages/func_e13xx.txt

+E: 11:pprint: Not enough arguments for format string
+E: 12:pprint: Too many arguments for format string
+E: 13:pprint: Mixing named and unnamed conversion specifiers in format string
+E: 14:pprint: Missing key 'PARG_2' in format string dictionary
+E: 16:pprint: Missing key 'PARG_2' in format string dictionary
+E: 17:pprint: Expected mapping for format string, not Tuple
+E: 18:pprint: Expected mapping for format string, not List
+E: 19:pprint: Unsupported format character 'z' (0x7a) at index 2
+E: 20:pprint: Format string ends in middle of conversion specifier
+W: 15:pprint: Unused key 'PARG_3' in format string dictionary
+W: 16:pprint: Format string dictionary key should be a string, not 2
+

test/messages/func_e65xx.txt

-E: 13:pprint: Too many arguments for logging format string
-E: 14:pprint: Too many arguments for logging format string
-E: 15:pprint: Logging format string ends in middle of conversion specifier
-E: 16:pprint: Not enough arguments for logging format string
-E: 17:pprint: Unsupported logging format character 'a' (0x61) at index 3
-E: 18:pprint: Too many arguments for logging format string

test/messages/func_e99xx.txt

-E: 11:pprint: Not enough arguments for format string
-E: 12:pprint: Too many arguments for format string
-E: 13:pprint: Mixing named and unnamed conversion specifiers in format string
-E: 14:pprint: Missing key 'PARG_2' in format string dictionary
-E: 16:pprint: Missing key 'PARG_2' in format string dictionary
-E: 17:pprint: Expected mapping for format string, not Tuple
-E: 18:pprint: Expected mapping for format string, not List
-E: 19:pprint: Unsupported format character 'z' (0x7a) at index 2
-E: 20:pprint: Format string ends in middle of conversion specifier
-W: 15:pprint: Unused key 'PARG_3' in format string dictionary
-W: 16:pprint: Format string dictionary key should be a string, not 2
-

test/messages/func_w1201.txt

+W: 12: Specify string format arguments as logging function parameters
+W: 13: Specify string format arguments as logging function parameters
+W: 14: Specify string format arguments as logging function parameters

test/messages/func_w6501.txt

-W: 12: Specify string format arguments as logging function parameters
-W: 13: Specify string format arguments as logging function parameters
-W: 14: Specify string format arguments as logging function parameters
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.