eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py

changeset 7611
d546c4e72f52
parent 7610
df7025fe26a3
child 7615
ca2949b1a29a
equal deleted inserted replaced
7610:df7025fe26a3 7611:d546c4e72f52
22 pycodestyle.register_check(NamingStyleChecker, NamingStyleChecker.Codes) 22 pycodestyle.register_check(NamingStyleChecker, NamingStyleChecker.Codes)
23 23
24 from DocStyleChecker import DocStyleChecker 24 from DocStyleChecker import DocStyleChecker
25 from MiscellaneousChecker import MiscellaneousChecker 25 from MiscellaneousChecker import MiscellaneousChecker
26 from ComplexityChecker import ComplexityChecker 26 from ComplexityChecker import ComplexityChecker
27 from Security.SecurityChecker import SecurityChecker
27 28
28 29
29 def initService(): 30 def initService():
30 """ 31 """
31 Initialize the service and return the entry point. 32 Initialize the service and return the entry point.
262 @type str 263 @type str
263 @param args arguments used by the codeStyleCheck function (list of 264 @param args arguments used by the codeStyleCheck function (list of
264 excludeMessages, includeMessages, repeatMessages, fixCodes, 265 excludeMessages, includeMessages, repeatMessages, fixCodes,
265 noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines, 266 noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines,
266 hangClosing, docType, codeComplexityArgs, miscellaneousArgs, 267 hangClosing, docType, codeComplexityArgs, miscellaneousArgs,
267 annotationArgs, errors, eol, encoding, backup) 268 annotationArgs, securityArgs, errors, eol, encoding, backup)
268 @type list of (str, str, bool, str, str, bool, int, list of (int, int), 269 @type list of (str, str, bool, str, str, bool, int, list of (int, int),
269 bool, str, dict, dict, list of str, str, str, bool) 270 bool, str, dict, dict, dict, list of str, str, str, bool)
270 @return tuple of statistics data and list of result dictionaries with 271 @return tuple of statistics data and list of result dictionaries with
271 keys: 272 keys:
272 <ul> 273 <ul>
273 <li>file: file name</li> 274 <li>file: file name</li>
274 <li>line: line_number</li> 275 <li>line: line_number</li>
283 </ul> 284 </ul>
284 @rtype tuple of (dict, list of dict) 285 @rtype tuple of (dict, list of dict)
285 """ 286 """
286 (excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes, 287 (excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes,
287 fixIssues, maxLineLength, maxDocLineLength, blankLines, hangClosing, 288 fixIssues, maxLineLength, maxDocLineLength, blankLines, hangClosing,
288 docType, codeComplexityArgs, miscellaneousArgs, annotationArgs, errors, 289 docType, codeComplexityArgs, miscellaneousArgs, annotationArgs,
289 eol, encoding, backup) = args 290 securityArgs, errors, eol, encoding, backup) = args
290 291
291 stats = {} 292 stats = {}
292 293
293 if fixIssues: 294 if fixIssues:
294 from CodeStyleFixer import CodeStyleFixer 295 from CodeStyleFixer import CodeStyleFixer
316 if excludeMessages: 317 if excludeMessages:
317 ignore = [i.strip() for i in 318 ignore = [i.strip() for i in
318 excludeMessages.split(',') if i.strip()] 319 excludeMessages.split(',') if i.strip()]
319 else: 320 else:
320 ignore = [] 321 ignore = []
322
323 # TODO: perform syntax check and report invalid syntax once for all
321 324
322 # check coding style 325 # check coding style
323 pycodestyle.BLANK_LINES_CONFIG = { 326 pycodestyle.BLANK_LINES_CONFIG = {
324 # Top level class and function. 327 # Top level class and function.
325 'top_level': blankLines[0], 328 'top_level': blankLines[0],
370 source, filename, select, ignore, [], repeatMessages, 373 source, filename, select, ignore, [], repeatMessages,
371 annotationArgs) 374 annotationArgs)
372 annotationsChecker.run() 375 annotationsChecker.run()
373 stats.update(annotationsChecker.counters) 376 stats.update(annotationsChecker.counters)
374 errors += annotationsChecker.errors 377 errors += annotationsChecker.errors
378
379 securityChecker = SecurityChecker(
380 source, filename, select, ignore, [], repeatMessages,
381 securityArgs)
382 securityChecker.run()
383 stats.update(securityChecker.counters)
384 errors += securityChecker.errors
375 385
376 errorsDict = {} 386 errorsDict = {}
377 for error in errors: 387 for error in errors:
378 if error["line"] > len(source): 388 if error["line"] > len(source):
379 error["line"] = len(source) 389 error["line"] = len(source)

eric ide

mercurial