19 Class implementing a checker for unused arguments, variables, ... . |
19 Class implementing a checker for unused arguments, variables, ... . |
20 """ |
20 """ |
21 |
21 |
22 Codes = [ |
22 Codes = [ |
23 ## Unused Arguments |
23 ## Unused Arguments |
24 "U100", |
24 "U-100", |
25 "U101", |
25 "U-101", |
26 ## Unused Globals |
26 ## Unused Globals |
27 "U200", |
27 "U-200", |
28 ] |
28 ] |
29 |
29 |
30 def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): |
30 def __init__(self, source, filename, tree, select, ignore, expected, repeat, args): |
31 """ |
31 """ |
32 Constructor |
32 Constructor |
62 |
62 |
63 # collection of detected errors |
63 # collection of detected errors |
64 self.errors = [] |
64 self.errors = [] |
65 |
65 |
66 checkersWithCodes = [ |
66 checkersWithCodes = [ |
67 (self.__checkUnusedArguments, ("U100", "U101")), |
67 (self.__checkUnusedArguments, ("U-100", "U-101")), |
68 (self.__checkUnusedGlobals, ("U200",)), |
68 (self.__checkUnusedGlobals, ("U-200",)), |
69 ] |
69 ] |
70 |
70 |
71 self.__checkers = [] |
71 self.__checkers = [] |
72 for checker, codes in checkersWithCodes: |
72 for checker, codes in checkersWithCodes: |
73 if any(not (code and self.__ignoreCode(code)) for code in codes): |
73 if any(not (code and self.__ignoreCode(code)) for code in codes): |
210 continue |
210 continue |
211 |
211 |
212 lineNumber = argument.lineno |
212 lineNumber = argument.lineno |
213 offset = argument.col_offset |
213 offset = argument.col_offset |
214 |
214 |
215 errorCode = "U101" if name.startswith("_") else "U100" |
215 errorCode = "U-101" if name.startswith("_") else "U-100" |
216 self.__error(lineNumber - 1, offset, errorCode, name) |
216 self.__error(lineNumber - 1, offset, errorCode, name) |
217 |
217 |
218 def __getDecoratorNames(self, functionNode): |
218 def __getDecoratorNames(self, functionNode): |
219 """ |
219 """ |
220 Private method to yield the decorator names of the function. |
220 Private method to yield the decorator names of the function. |
404 globalVariables = self.__extractGlobalVariables() |
404 globalVariables = self.__extractGlobalVariables() |
405 |
405 |
406 for varId, loads in loadCounter.getLoads(): |
406 for varId, loads in loadCounter.getLoads(): |
407 if varId in globalVariables and loads == 0: |
407 if varId in globalVariables and loads == 0: |
408 storeInfo = loadCounter.getStoreInfo(varId) |
408 storeInfo = loadCounter.getStoreInfo(varId) |
409 errorInfo = (storeInfo.lineno - 1, storeInfo.offset, "U200", varId) |
409 errorInfo = (storeInfo.lineno - 1, storeInfo.offset, "U-200", varId) |
410 errors[varId] = errorInfo |
410 errors[varId] = errorInfo |
411 |
411 |
412 for node in self.__tree.body[::-1]: |
412 for node in self.__tree.body[::-1]: |
413 if isinstance(node, ast.Assign): |
413 if isinstance(node, ast.Assign): |
414 for target in node.targets: |
414 for target in node.targets: |