Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: third_party/pylint/checkers/__init__.py

Issue 753543006: pylint: upgrade to 1.4.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/pylint/__pkginfo__.py ('k') | third_party/pylint/checkers/base.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE). 1 # Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr 2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 # 3 #
4 # This program is free software; you can redistribute it and/or modify it under 4 # This program is free software; you can redistribute it and/or modify it under
5 # the terms of the GNU General Public License as published by the Free Software 5 # the terms of the GNU General Public License as published by the Free Software
6 # Foundation; either version 2 of the License, or (at your option) any later 6 # Foundation; either version 2 of the License, or (at your option) any later
7 # version. 7 # version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT 9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
(...skipping 12 matching lines...) Expand all
23 05: misc 23 05: misc
24 06: variables 24 06: variables
25 07: exceptions 25 07: exceptions
26 08: similar 26 08: similar
27 09: design_analysis 27 09: design_analysis
28 10: newstyle 28 10: newstyle
29 11: typecheck 29 11: typecheck
30 12: logging 30 12: logging
31 13: string_format 31 13: string_format
32 14: string_constant 32 14: string_constant
33 15-50: not yet used: reserved for future internal checkers. 33 15: stdlib
34 16: python3
35 17-50: not yet used: reserved for future internal checkers.
34 51-99: perhaps used: reserved for external checkers 36 51-99: perhaps used: reserved for external checkers
35 37
36 The raw_metrics checker has no number associated since it doesn't emit any 38 The raw_metrics checker has no number associated since it doesn't emit any
37 messages nor reports. XXX not true, emit a 07 report ! 39 messages nor reports. XXX not true, emit a 07 report !
38 40
39 """ 41 """
40 42
41 import sys 43 import sys
42 import tokenize 44 import tokenize
43 import warnings 45 import warnings
44 46
45 from logilab.common.configuration import OptionsProviderMixIn 47 from logilab.common.configuration import OptionsProviderMixIn
46 48
47 from pylint.reporters import diff_string 49 from pylint.reporters import diff_string
48 from pylint.utils import register_plugins 50 from pylint.utils import register_plugins
51 from pylint.interfaces import UNDEFINED
52
49 53
50 def table_lines_from_stats(stats, old_stats, columns): 54 def table_lines_from_stats(stats, old_stats, columns):
51 """get values listed in <columns> from <stats> and <old_stats>, 55 """get values listed in <columns> from <stats> and <old_stats>,
52 and return a formated list of values, designed to be given to a 56 and return a formated list of values, designed to be given to a
53 ureport.Table object 57 ureport.Table object
54 """ 58 """
55 lines = [] 59 lines = []
56 for m_type in columns: 60 for m_type in columns:
57 new = stats[m_type] 61 new = stats[m_type]
58 format = str 62 format = str # pylint: disable=redefined-builtin
59 if isinstance(new, float): 63 if isinstance(new, float):
60 format = lambda num: '%.3f' % num 64 format = lambda num: '%.3f' % num
61 old = old_stats.get(m_type) 65 old = old_stats.get(m_type)
62 if old is not None: 66 if old is not None:
63 diff_str = diff_string(old, new) 67 diff_str = diff_string(old, new)
64 old = format(old) 68 old = format(old)
65 else: 69 else:
66 old, diff_str = 'NC', 'NC' 70 old, diff_str = 'NC', 'NC'
67 lines += (m_type.replace('_', ' '), format(new), old, diff_str) 71 lines += (m_type.replace('_', ' '), format(new), old, diff_str)
68 return lines 72 return lines
69 73
70 74
71 class BaseChecker(OptionsProviderMixIn): 75 class BaseChecker(OptionsProviderMixIn):
72 """base class for checkers""" 76 """base class for checkers"""
73 # checker name (you may reuse an existing one) 77 # checker name (you may reuse an existing one)
74 name = None 78 name = None
75 # options level (0 will be displaying in --help, 1 in --long-help) 79 # options level (0 will be displaying in --help, 1 in --long-help)
76 level = 1 80 level = 1
77 # ordered list of options to control the ckecker behaviour 81 # ordered list of options to control the ckecker behaviour
78 options = () 82 options = ()
79 # messages issued by this checker 83 # messages issued by this checker
80 msgs = {} 84 msgs = {}
81 # reports issued by this checker 85 # reports issued by this checker
82 reports = () 86 reports = ()
87 # mark this checker as enabled or not.
88 enabled = True
83 89
84 def __init__(self, linter=None): 90 def __init__(self, linter=None):
85 """checker instances should have the linter as argument 91 """checker instances should have the linter as argument
86 92
87 linter is an object implementing ILinter 93 linter is an object implementing ILinter
88 """ 94 """
89 self.name = self.name.lower() 95 self.name = self.name.lower()
90 OptionsProviderMixIn.__init__(self) 96 OptionsProviderMixIn.__init__(self)
91 self.linter = linter 97 self.linter = linter
92 98
93 def add_message(self, msg_id, line=None, node=None, args=None): 99 def add_message(self, msg_id, line=None, node=None, args=None, confidence=UN DEFINED):
94 """add a message of a given type""" 100 """add a message of a given type"""
95 self.linter.add_message(msg_id, line, node, args) 101 self.linter.add_message(msg_id, line, node, args, confidence)
96 102
97 # dummy methods implementing the IChecker interface 103 # dummy methods implementing the IChecker interface
98 104
99 def open(self): 105 def open(self):
100 """called before visiting project (i.e set of modules)""" 106 """called before visiting project (i.e set of modules)"""
101 107
102 def close(self): 108 def close(self):
103 """called after visiting project (i.e set of modules)""" 109 """called after visiting project (i.e set of modules)"""
104 110
105 111
106 class BaseRawChecker(BaseChecker):
107 """base class for raw checkers"""
108
109 def process_module(self, node):
110 """process a module
111
112 the module's content is accessible via the stream object
113
114 stream must implement the readline method
115 """
116 warnings.warn("Modules that need access to the tokens should "
117 "use the ITokenChecker interface.",
118 DeprecationWarning)
119 stream = node.file_stream
120 stream.seek(0) # XXX may be removed with astroid > 0.23
121 if sys.version_info <= (3, 0):
122 self.process_tokens(tokenize.generate_tokens(stream.readline))
123 else:
124 self.process_tokens(tokenize.tokenize(stream.readline))
125
126 def process_tokens(self, tokens):
127 """should be overridden by subclasses"""
128 raise NotImplementedError()
129
130
131 class BaseTokenChecker(BaseChecker): 112 class BaseTokenChecker(BaseChecker):
132 """Base class for checkers that want to have access to the token stream.""" 113 """Base class for checkers that want to have access to the token stream."""
133 114
134 def process_tokens(self, tokens): 115 def process_tokens(self, tokens):
135 """Should be overridden by subclasses.""" 116 """Should be overridden by subclasses."""
136 raise NotImplementedError() 117 raise NotImplementedError()
137 118
138 119
139 def initialize(linter): 120 def initialize(linter):
140 """initialize linter with checkers in this package """ 121 """initialize linter with checkers in this package """
141 register_plugins(linter, __path__[0]) 122 register_plugins(linter, __path__[0])
142 123
143 __all__ = ('BaseChecker', 'initialize') 124 __all__ = ('BaseChecker', 'initialize')
OLDNEW
« no previous file with comments | « third_party/pylint/__pkginfo__.py ('k') | third_party/pylint/checkers/base.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698