UtilitiesPython2/CodeStyleChecker.py

changeset 3165
400234200cd6
parent 3160
209a07d7e401
equal deleted inserted replaced
3164:a027fc190f82 3165:400234200cd6
118 ignore = [i.strip() for i in ignore.split(',') 118 ignore = [i.strip() for i in ignore.split(',')
119 if i.strip()] 119 if i.strip()]
120 else: 120 else:
121 ignore = [] 121 ignore = []
122 122
123 # check coding style 123 try:
124 styleGuide = pep8.StyleGuide( 124 # check coding style
125 reporter=CodeStyleReport, 125 styleGuide = pep8.StyleGuide(
126 repeat=repeat, 126 reporter=CodeStyleReport,
127 select=select, 127 repeat=repeat,
128 ignore=ignore, 128 select=select,
129 max_line_length=max_line_length, 129 ignore=ignore,
130 hang_closing=hang_closing, 130 max_line_length=max_line_length,
131 ) 131 hang_closing=hang_closing,
132 report = styleGuide.check_files([filename]) 132 )
133 133 report = styleGuide.check_files([filename])
134 # check documentation style 134
135 docStyleChecker = DocStyleChecker( 135 # check documentation style
136 source, filename, select, ignore, [], repeat, 136 docStyleChecker = DocStyleChecker(
137 maxLineLength=max_line_length, docType=docType) 137 source, filename, select, ignore, [], repeat,
138 docStyleChecker.run() 138 maxLineLength=max_line_length, docType=docType)
139 139 docStyleChecker.run()
140 errors = report.errors + docStyleChecker.errors 140
141 141 errors = report.errors + docStyleChecker.errors
142 if len(errors) > 0: 142
143 errors.sort(key=lambda a: a[1]) 143 if len(errors) > 0:
144 for error in errors: 144 errors.sort(key=lambda a: a[1])
145 fname, lineno, position, code, args = error 145 for error in errors:
146 print "PEP8" 146 fname, lineno, position, code, args = error
147 print fname 147 print "PEP8"
148 print lineno 148 print fname
149 print position 149 print lineno
150 print code 150 print position
151 print len(args) 151 print code
152 for a in args: 152 print len(args)
153 print a 153 for a in args:
154 print "PEP8_STATISTICS" 154 print a
155 for key in report.counters: 155 print "PEP8_STATISTICS"
156 if key.startswith(("E", "N", "W")): 156 for key in report.counters:
157 print key, report.counters[key] 157 if key.startswith(("E", "N", "W")):
158 for key in docStyleChecker.counters: 158 print key, report.counters[key]
159 if key.startswith("D"): 159 for key in docStyleChecker.counters:
160 print key, docStyleChecker.counters[key] 160 if key.startswith("D"):
161 else: 161 print key, docStyleChecker.counters[key]
162 print "NO_PEP8" 162 else:
163 print filename 163 print "NO_PEP8"
164 print filename
165 except StandardError, msg:
166 import traceback
167 print "EXCEPTION"
168 print ""
169 print "Error in eric5 code:"
170 print traceback.format_exc()
171 sys.exit(1)
164 172
165 # 173 #
166 # eflag: FileType = Python2 174 # eflag: FileType = Python2

eric ide

mercurial