src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py

branch
eric7
changeset 10046
35b27af462ef
parent 10041
67c8efa6d098
child 10052
041d0785dd42
equal deleted inserted replaced
10045:f5c57f8d17a4 10046:35b27af462ef
18 from CodeStyleFixer import CodeStyleFixer 18 from CodeStyleFixer import CodeStyleFixer
19 from Complexity.ComplexityChecker import ComplexityChecker 19 from Complexity.ComplexityChecker import ComplexityChecker
20 from DocStyle.DocStyleChecker import DocStyleChecker 20 from DocStyle.DocStyleChecker import DocStyleChecker
21 from Imports.ImportsChecker import ImportsChecker 21 from Imports.ImportsChecker import ImportsChecker
22 from Miscellaneous.MiscellaneousChecker import MiscellaneousChecker 22 from Miscellaneous.MiscellaneousChecker import MiscellaneousChecker
23 from NameOrder.NameOrderChecker import NameOrderChecker
23 from Naming.NamingStyleChecker import NamingStyleChecker 24 from Naming.NamingStyleChecker import NamingStyleChecker
24 from PathLib.PathlibChecker import PathlibChecker 25 from PathLib.PathlibChecker import PathlibChecker
25 from Security.SecurityChecker import SecurityChecker 26 from Security.SecurityChecker import SecurityChecker
26 from Simplify.SimplifyChecker import SimplifyChecker 27 from Simplify.SimplifyChecker import SimplifyChecker
27 28
110 if endPos >= 0: 111 if endPos >= 0:
111 comment = comment[:endPos] 112 comment = comment[:endPos]
112 if comment.startswith(("noqa:", "NOQA:")): 113 if comment.startswith(("noqa:", "NOQA:")):
113 flags = [ 114 flags = [
114 "noqa:{0}".format(f.strip()) 115 "noqa:{0}".format(f.strip())
115 for f in comment[len("noqa:"):].split(",") 116 for f in comment[len("noqa:") :].split(",")
116 ] 117 ]
117 else: 118 else:
118 flags = [ 119 flags = [
119 f.strip() 120 f.strip()
120 for f in comment.split() 121 for f in comment.split()
153 if flag.startswith("__IGNORE_WARNING_"): 154 if flag.startswith("__IGNORE_WARNING_"):
154 ignoredCode = flag[2:-2].rsplit("_", 1)[-1] 155 ignoredCode = flag[2:-2].rsplit("_", 1)[-1]
155 if code.startswith(ignoredCode): 156 if code.startswith(ignoredCode):
156 return True 157 return True
157 elif flag.startswith("noqa:"): 158 elif flag.startswith("noqa:"):
158 ignoredCode = flag[len("noqa:"):].strip() 159 ignoredCode = flag[len("noqa:") :].strip()
159 if code.startswith(ignoredCode): 160 if code.startswith(ignoredCode):
160 return True 161 return True
161 162
162 return False 163 return False
163 164
189 @type str 190 @type str
190 @param args arguments used by the codeStyleCheck function (list of 191 @param args arguments used by the codeStyleCheck function (list of
191 excludeMessages, includeMessages, repeatMessages, fixCodes, 192 excludeMessages, includeMessages, repeatMessages, fixCodes,
192 noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines, 193 noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines,
193 hangClosing, docType, codeComplexityArgs, miscellaneousArgs, 194 hangClosing, docType, codeComplexityArgs, miscellaneousArgs,
194 annotationArgs, securityArgs, importsArgs, errors, eol, encoding, 195 annotationArgs, securityArgs, importsArgs, nameOrderArgs, errors, eol, encoding,
195 backup) 196 backup)
196 @type list of (str, str, bool, str, str, bool, int, list of (int, int), 197 @type list of (str, str, bool, str, str, bool, int, list of (int, int),
197 bool, str, dict, dict, dict, dict, list of str, str, str, bool) 198 bool, str, dict, dict, dict, dict, dict, list of str, str, str, bool)
198 @return tuple of statistics (dict) and list of results (tuple for each 199 @return tuple of statistics (dict) and list of results (tuple for each
199 found violation of style (lineno, position, text, ignored, fixed, 200 found violation of style (lineno, position, text, ignored, fixed,
200 autofixing, fixedMsg)) 201 autofixing, fixedMsg))
201 @rtype tuple of (dict, list of tuples of (int, int, str, bool, bool, bool, 202 @rtype tuple of (dict, list of tuples of (int, int, str, bool, bool, bool,
202 str)) 203 str))
353 @type str 354 @type str
354 @param args arguments used by the codeStyleCheck function (list of 355 @param args arguments used by the codeStyleCheck function (list of
355 excludeMessages, includeMessages, repeatMessages, fixCodes, 356 excludeMessages, includeMessages, repeatMessages, fixCodes,
356 noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines, 357 noFixCodes, fixIssues, maxLineLength, maxDocLineLength, blankLines,
357 hangClosing, docType, codeComplexityArgs, miscellaneousArgs, 358 hangClosing, docType, codeComplexityArgs, miscellaneousArgs,
358 annotationArgs, securityArgs, importsArgs, errors, eol, encoding, 359 annotationArgs, securityArgs, importsArgs, nameOrderArgs, errors, eol, encoding,
359 backup) 360 backup)
360 @type list of (str, str, bool, str, str, bool, int, list of (int, int), 361 @type list of (str, str, bool, str, str, bool, int, list of (int, int),
361 bool, str, dict, dict, dict, dict, list of str, str, str, bool) 362 bool, str, dict, dict, dict, dict, dict, list of str, str, str, bool)
362 @return tuple of statistics data and list of result dictionaries with 363 @return tuple of statistics data and list of result dictionaries with
363 keys: 364 keys:
364 <ul> 365 <ul>
365 <li>file: file name</li> 366 <li>file: file name</li>
366 <li>line: line_number</li> 367 <li>line: line_number</li>
390 codeComplexityArgs, 391 codeComplexityArgs,
391 miscellaneousArgs, 392 miscellaneousArgs,
392 annotationArgs, 393 annotationArgs,
393 securityArgs, 394 securityArgs,
394 importsArgs, 395 importsArgs,
396 nameOrderArgs,
395 errors, 397 errors,
396 eol, 398 eol,
397 encoding, 399 encoding,
398 backup, 400 backup,
399 ) = args 401 ) = args
539 source, filename, tree, select, ignore, [], repeatMessages, importsArgs 541 source, filename, tree, select, ignore, [], repeatMessages, importsArgs
540 ) 542 )
541 importsChecker.run() 543 importsChecker.run()
542 stats.update(importsChecker.counters) 544 stats.update(importsChecker.counters)
543 errors += importsChecker.errors 545 errors += importsChecker.errors
546
547 # check name ordering
548 nameOrderChecker = NameOrderChecker(
549 source,
550 filename,
551 tree,
552 select,
553 ignore,
554 [],
555 repeatMessages,
556 nameOrderArgs,
557 )
558 nameOrderChecker.run()
559 stats.update(nameOrderChecker.counters)
560 errors += nameOrderChecker.errors
544 561
545 elif syntaxError: 562 elif syntaxError:
546 errors = [syntaxError] 563 errors = [syntaxError]
547 stats.update(syntaxStats) 564 stats.update(syntaxStats)
548 565

eric ide

mercurial