102 if endPos >= 0: |
102 if endPos >= 0: |
103 comment = comment[:endPos] |
103 comment = comment[:endPos] |
104 flags = [f.strip() for f in comment.split() |
104 flags = [f.strip() for f in comment.split() |
105 if (f.startswith("__") and f.endswith("__"))] |
105 if (f.startswith("__") and f.endswith("__"))] |
106 return flags |
106 return flags |
|
107 |
|
108 |
|
109 def ignoreCode(code, lineFlags): |
|
110 """ |
|
111 Function to check, if the given code should be ignored as per line flags. |
|
112 |
|
113 @param code error code to be checked |
|
114 @type str |
|
115 @param lineFlags list of line flags to check against |
|
116 @type list of str |
|
117 """ |
|
118 if lineFlags: |
|
119 |
|
120 if "__IGNORE_WARNING__" in lineFlags: |
|
121 # ignore all warning codes |
|
122 return True |
|
123 |
|
124 for flag in lineFlags: |
|
125 # check individual warning code |
|
126 if flag.startswith("__IGNORE_WARNING_"): |
|
127 ignoredCode = flag[2:-2].rsplit("_", 1)[-1] |
|
128 if code.startswith(ignoredCode): |
|
129 return True |
|
130 |
|
131 return False |
107 |
132 |
108 |
133 |
109 def codeStyleCheck(filename, source, args): |
134 def codeStyleCheck(filename, source, args): |
110 """ |
135 """ |
111 Do the code style check and/ or fix found errors. |
136 Do the code style check and/ or fix found errors. |
303 try: |
328 try: |
304 lineFlags += extractLineFlags(source[lineno].strip(), |
329 lineFlags += extractLineFlags(source[lineno].strip(), |
305 flagsLine=True) |
330 flagsLine=True) |
306 except IndexError: |
331 except IndexError: |
307 pass |
332 pass |
308 if "__IGNORE_WARNING__" not in lineFlags and \ |
333 if not ignoreCode(code, lineFlags): |
309 "__IGNORE_WARNING_{0}__".format(code) not in lineFlags: |
|
310 if fixer: |
334 if fixer: |
311 res, msg, id_ = fixer.fixIssue(lineno, position, text) |
335 res, msg, id_ = fixer.fixIssue(lineno, position, text) |
312 if res == -1: |
336 if res == -1: |
313 itm = [lineno, position, text] |
337 itm = [lineno, position, text] |
314 deferredFixes[id_] = itm |
338 deferredFixes[id_] = itm |