Plugins/CheckerPlugins/Pep8/Pep8Checker.py

changeset 2863
62171fa4a6a4
parent 2862
a1448560d7dc
child 2864
d973dab8b715
equal deleted inserted replaced
2862:a1448560d7dc 2863:62171fa4a6a4
6 """ 6 """
7 Module implementing the PEP 8 checker. 7 Module implementing the PEP 8 checker.
8 """ 8 """
9 9
10 import os 10 import os
11 ##import optparse
12 11
13 from PyQt4.QtCore import QProcess, QCoreApplication 12 from PyQt4.QtCore import QProcess, QCoreApplication
14 13
15 from . import pep8 14 from . import pep8
16 15
18 import Utilities 17 import Utilities
19 18
20 from eric5config import getConfig 19 from eric5config import getConfig
21 20
22 21
23 ##class Pep8Checker(pep8.Checker):
24 ## """
25 ## Class implementing the PEP 8 checker.
26 ## """
27 ## def __init__(self, filename, lines, repeat=False,
28 ## select="", ignore=""):
29 ## """
30 ## Constructor
31 ##
32 ## @param filename name of the file to check (string)
33 ## @param lines source of the file (list of strings)
34 ## @keyparam repeat flag indicating to repeat message categories (boolean)
35 ## @keyparam select list of message IDs to check for
36 ## (comma separated string)
37 ## @keyparam ignore list of message IDs to ignore
38 ## (comma separated string)
39 ## """
40 ## pep8.options = optparse.Values()
41 ##
42 ## pep8.options.verbose = 0
43 ##
44 ## pep8.options.repeat = repeat
45 ## if select:
46 ## pep8.options.select = [s.strip() for s in select.split(',')
47 ## if s.strip()]
48 ## else:
49 ## pep8.options.select = []
50 ## if ignore:
51 ## pep8.options.ignore = [i.strip() for i in ignore.split(',')
52 ## if i.strip()]
53 ## else:
54 ## pep8.options.ignore = []
55 ## pep8.options.physical_checks = pep8.find_checks('physical_line')
56 ## pep8.options.logical_checks = pep8.find_checks('logical_line')
57 ## pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
58 ## pep8.options.messages = {}
59 ##
60 ## pep8.Checker.__init__(self, filename, lines)
61 ##
62 ## self.messages = []
63 ## self.statistics = {}
64 ##
65 ## def __ignore_code(self, code):
66 ## """
67 ## Private method to check, if the message for the given code should
68 ## be ignored.
69 ##
70 ## If codes are selected and the code has a selected prefix and does not
71 ## have an ignored prefix, it is not ignored. If codes are selected and
72 ## the code does not have a selected prefix, it is ignored. If no codes
73 ## are selected, the code is ignored, if it has a prefix, that is
74 ## contained in the ignored codes.
75 ##
76 ## @param code code to be checked (string)
77 ## @return flag indicating, that the code should be ignored (boolean)
78 ## """
79 ## if pep8.options.select:
80 ## if code.startswith(tuple(pep8.options.select)):
81 ## if code.startswith(tuple(pep8.options.ignore)):
82 ## return True
83 ## else:
84 ## return False
85 ## else:
86 ## return True
87 ## else:
88 ## if code.startswith(tuple(pep8.options.ignore)):
89 ## return True
90 ## else:
91 ## return False
92 ##
93 ## def report_error_args(self, line_number, offset, code, check, *args):
94 ## """
95 ## Public method to collect the error messages.
96 ##
97 ## @param line_number line number of the issue (integer)
98 ## @param offset position within line of the issue (integer)
99 ## @param code message code (string)
100 ## @param check reference to the checker function (function)
101 ## @param args arguments for the message (list)
102 ## """
103 ## if self.__ignore_code(code):
104 ## return
105 ##
106 ## text = pep8.getMessage(code, *args)
107 ## if code in self.statistics:
108 ## self.statistics[code] += 1
109 ## else:
110 ## self.statistics[code] = 1
111 ## self.file_errors += 1
112 ## if self.statistics[code] == 1 or pep8.options.repeat:
113 ## self.messages.append(
114 ## (self.filename, self.line_offset + line_number,
115 ## offset + 1, text)
116 ## )
117 ##
118 ##
119 class Pep8Py2Checker(object): 22 class Pep8Py2Checker(object):
120 """ 23 """
121 Class implementing the PEP 8 checker interface for Python 2. 24 Class implementing the PEP 8 checker interface for Python 2.
122 """ 25 """
123 def __init__(self, filename, lines, repeat=False, 26 def __init__(self, filename, lines, repeat=False,

eric ide

mercurial