72 (self.filename, line_number, offset, (code, args)) |
72 (self.filename, line_number, offset, (code, args)) |
73 ) |
73 ) |
74 return code |
74 return code |
75 |
75 |
76 |
76 |
77 def extractLineFlags(line, startComment="#", endComment=""): |
77 def extractLineFlags(line, startComment="#", endComment="", flagsLine=False): |
78 """ |
78 """ |
79 Function to extract flags starting and ending with '__' from a line |
79 Function to extract flags starting and ending with '__' from a line |
80 comment. |
80 comment. |
81 |
81 |
82 @param line line to extract flags from (string) |
82 @param line line to extract flags from (string) |
83 @keyparam startComment string identifying the start of the comment (string) |
83 @keyparam startComment string identifying the start of the comment (string) |
84 @keyparam endComment string identifying the end of a comment (string) |
84 @keyparam endComment string identifying the end of a comment (string) |
|
85 @keyparam flagsLine flag indicating to check for a flags only line (bool) |
85 @return list containing the extracted flags (list of strings) |
86 @return list containing the extracted flags (list of strings) |
86 """ |
87 """ |
87 flags = [] |
88 flags = [] |
88 |
89 |
89 pos = line.rfind(startComment) |
90 if not flagsLine or ( |
90 if pos >= 0: |
91 flagsLine and line.strip().startswith(startComment)): |
91 comment = line[pos + len(startComment):].strip() |
92 pos = line.rfind(startComment) |
92 if endComment: |
93 if pos >= 0: |
93 comment = comment.replace("endComment", "") |
94 comment = line[pos + len(startComment):].strip() |
94 flags = [f.strip() for f in comment.split() |
95 if endComment: |
95 if (f.startswith("__") and f.endswith("__"))] |
96 endPos = line.rfind(endComment) |
|
97 if endPos >= 0: |
|
98 comment = comment[:endPos] |
|
99 flags = [f.strip() for f in comment.split() |
|
100 if (f.startswith("__") and f.endswith("__"))] |
96 return flags |
101 return flags |
97 |
102 |
98 |
103 |
99 def codeStyleCheck(filename, source, args): |
104 def codeStyleCheck(filename, source, args): |
100 """ |
105 """ |
272 errors.sort(key=lambda x: x[0], reverse=True) |
277 errors.sort(key=lambda x: x[0], reverse=True) |
273 for position, text in errors: |
278 for position, text in errors: |
274 if source: |
279 if source: |
275 code = text[0] |
280 code = text[0] |
276 lineFlags = extractLineFlags(source[lineno - 1].strip()) |
281 lineFlags = extractLineFlags(source[lineno - 1].strip()) |
|
282 try: |
|
283 lineFlags += extractLineFlags(source[lineno].strip(), |
|
284 flagsLine=True) |
|
285 except IndexError: |
|
286 pass |
277 if "__IGNORE_WARNING__" not in lineFlags and \ |
287 if "__IGNORE_WARNING__" not in lineFlags and \ |
278 "__IGNORE_WARNING_{0}__".format(code) not in lineFlags: |
288 "__IGNORE_WARNING_{0}__".format(code) not in lineFlags: |
279 if fixer: |
289 if fixer: |
280 res, msg, id_ = fixer.fixIssue(lineno, position, text) |
290 res, msg, id_ = fixer.fixIssue(lineno, position, text) |
281 if res == -1: |
291 if res == -1: |