pylint.diff

download
Index: pylint-0.7.0/utils.py
===================================================================
--- pylint-0.7.0/utils.py	(revision 596)
+++ pylint-0.7.0/utils.py	(revision 599)
@@ -20,6 +20,7 @@
 
 __revision__ = "$Id: utils.py,v 1.10 2005/04/15 10:40:07 syt Exp $"
 
+import re
 from os import linesep
 
 from logilab.common.astng import Module
@@ -133,10 +134,29 @@
     def disable_message(self, msg_id, scope='package', line=None):
         """don't output message of the given id"""
         assert scope in ('package', 'module')
+
+        match_line = 0
+        match = re.match("([A-Z]\d+)(\(([+\-]?\d+)\))?", msg_id)
+        if match is not None:
+            msg_id = match.group(1)
+            if match.group(3) is not None:
+                if match.group(3)[0] in "+-":
+                    assert line is not None
+                    match_line = line + int(match.group(3))
+                else:
+                    match_line = int(match.group(3))
+
         msg_id = self.check_message_id(msg_id)
         if scope == 'module':
             self.add_message('I0011', line=line, args=msg_id)
-            self._module_msgs_state[msg_id] = False
+            if match_line == 0:
+                # disable module wide
+                self._module_msgs_state[msg_id] = False
+            else:
+                try:
+                    self._module_msgs_state[msg_id].append(match_line)
+                except KeyError:
+                    self._module_msgs_state[msg_id] = [match_line]
         else:
             msgs = self._msgs_state
             msgs[msg_id] = False
@@ -184,7 +204,7 @@
             raise UnknownMessage('No such message id %s' % msg_id)
         return msg_id
 
-    def is_message_enabled(self, msg_id):
+    def is_message_enabled(self, msg_id, line=None):
         """return true if the message associated to the given message id is
         enabled
         """
@@ -195,7 +215,13 @@
             if not self._msg_cats_state.get(msg_id[0], True):
                 return False
         try:
-            return self._module_msgs_state[msg_id]
+            state = self._module_msgs_state[msg_id]
+            if isinstance(state, list) and line is not None:
+                return line not in state
+            elif not isinstance(state, list):
+                return state
+            else:
+                return True
         except (KeyError, TypeError):
             return self._msgs_state.get(msg_id, True)
         
@@ -207,8 +233,12 @@
         astng checkers should provide the node argument, raw checkers should
         provide the line argument.
         """
+        if line is None and node is not None:
+            line = node.lineno or node.get_statement().lineno
+            #if not isinstance(node, Module):
+            #    assert line > 0, node.__class__
         # should this message be displayed
-        if not self.is_message_enabled(msg_id):
+        if not self.is_message_enabled(msg_id, line):
             return        
         # update stats
         msg_cat = MSG_TYPES[msg_id[0]]
@@ -222,10 +252,6 @@
         # expand message ?
         if args:
             msg %= args
-        if line is None and node is not None:
-            line = node.lineno or node.get_statement().lineno
-            #if not isinstance(node, Module):
-            #    assert line > 0, node.__class__
         # get module and object
         if node is None:
             module, obj = self.current_name, ''
Index: pylint-0.7.0/lint.py
===================================================================
--- pylint-0.7.0/lint.py	(revision 596)
+++ pylint-0.7.0/lint.py	(revision 599)
@@ -63,7 +63,7 @@
 from pylint.__pkginfo__ import version
 
 
-OPTION_RGX = re.compile('#*\s*pylint:(.*)')
+OPTION_RGX = re.compile('\s*#*\s*pylint:(.*)')
 REPORTER_OPT_MAP = {'html': HTMLReporter,
                     'parseable': TextReporter2,
                     'color': ColorizedTextReporter}
@@ -334,8 +334,8 @@
         newline = tokenize.NEWLINE
         #line_num = 0
         for (tok_type, _, start, _, line) in tokens:
-            if tok_type not in (comment, newline):
-                break
+            #if tok_type not in (comment, newline):
+            #    break
             #if start[0] == line_num:
             #    continue
             match = OPTION_RGX.match(line)
download