136 return False |
136 return False |
137 |
137 |
138 |
138 |
139 def codeStyleCheck(filename, source, args): |
139 def codeStyleCheck(filename, source, args): |
140 """ |
140 """ |
141 Do the code style check and/ or fix found errors. |
141 Do the code style check and/or fix found errors. |
142 |
142 |
143 @param filename source filename (string) |
143 @param filename source filename |
144 @param source string containing the code to check (string) |
144 @type str |
|
145 @param source string containing the code to check |
|
146 @type str |
145 @param args arguments used by the codeStyleCheck function (list of |
147 @param args arguments used by the codeStyleCheck function (list of |
146 excludeMessages (str), includeMessages (str), repeatMessages |
148 excludeMessages, includeMessages, repeatMessages, fixCodes, |
147 (bool), fixCodes (str), noFixCodes (str), fixIssues (bool), |
149 noFixCodes, fixIssues, maxLineLength, blankLines, hangClosing, |
148 maxLineLength (int), hangClosing (bool), docType (str), errors |
150 docType, codeComplexityArgs, miscellaneousArgs, errors, eol, |
149 (list of str), eol (str), encoding (str), backup (bool)) |
151 encoding, backup) |
150 @return tuple of stats (dict) and results (tuple for each found violation |
152 @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
151 of style (tuple of lineno (int), position (int), text (str), ignored |
153 bool, str, dict, dict, list of str, str, str, bool) |
152 (bool), fixed (bool), autofixing (bool), fixedMsg (str))) |
154 @return tuple of statistics (dict) and list of results (tuple for each |
|
155 found violation of style (lineno, position, text, ignored, fixed, |
|
156 autofixing, fixedMsg)) |
|
157 @rtype tuple of (dict, list of tuples of (int, int, str, bool, bool, bool, |
|
158 str)) |
153 """ |
159 """ |
154 return __checkCodeStyle(filename, source, args) |
160 return __checkCodeStyle(filename, source, args) |
155 |
161 |
156 |
162 |
157 def codeStyleBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0): |
163 def codeStyleBatchCheck(argumentsList, send, fx, cancelled, maxProcesses=0): |
239 def __checkCodeStyle(filename, source, args): |
245 def __checkCodeStyle(filename, source, args): |
240 """ |
246 """ |
241 Private module function to perform the code style check and/or fix |
247 Private module function to perform the code style check and/or fix |
242 found errors. |
248 found errors. |
243 |
249 |
244 @param filename source filename (string) |
250 @param filename source filename |
245 @param source string containing the code to check (string) |
251 @type str |
|
252 @param source string containing the code to check |
|
253 @type str |
246 @param args arguments used by the codeStyleCheck function (list of |
254 @param args arguments used by the codeStyleCheck function (list of |
247 excludeMessages (str), includeMessages (str), repeatMessages |
255 excludeMessages, includeMessages, repeatMessages, fixCodes, |
248 (bool), fixCodes (str), noFixCodes (str), fixIssues (bool), |
256 noFixCodes, fixIssues, maxLineLength, blankLines, hangClosing, |
249 maxLineLength (int), hangClosing (bool), docType (str), dictionary |
257 docType, codeComplexityArgs, miscellaneousArgs, errors, eol, |
250 with arguments for the code complexity checker (dict), dictionary |
258 encoding, backup) |
251 with arguments for the miscellaneous checker (dict), errors (list |
259 @type list of (str, str, bool, str, str, bool, int, list of (int, int), |
252 of str), eol (str), encoding (str), backup (bool)) |
260 bool, str, dict, dict, list of str, str, str, bool) |
253 @return tuple of statistics (dict) and results (tuple for each found |
261 @return tuple of statistics (dict) and list of results (tuple for each |
254 violation of style (tuple of lineno (int), position (int), text (str), |
262 found violation of style (lineno, position, text, ignored, fixed, |
255 ignored (bool), fixed (bool), autofixing (bool), fixedMsg (str))) |
263 autofixing, fixedMsg)) |
|
264 @rtype tuple of (dict, list of tuples of (int, int, str, bool, bool, bool, |
|
265 str)) |
256 """ |
266 """ |
257 (excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes, |
267 (excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes, |
258 fixIssues, maxLineLength, hangClosing, docType, codeComplexityArgs, |
268 fixIssues, maxLineLength, blankLines, hangClosing, docType, |
259 miscellaneousArgs, errors, eol, encoding, backup) = args |
269 codeComplexityArgs, miscellaneousArgs, errors, eol, encoding, |
|
270 backup) = args |
260 |
271 |
261 stats = {} |
272 stats = {} |
262 |
273 |
263 if fixIssues: |
274 if fixIssues: |
264 from CodeStyleFixer import CodeStyleFixer |
275 from CodeStyleFixer import CodeStyleFixer |
265 fixer = CodeStyleFixer( |
276 fixer = CodeStyleFixer( |
266 filename, source, fixCodes, noFixCodes, |
277 filename, source, fixCodes, noFixCodes, |
267 maxLineLength, True, eol, backup) # always fix in place |
278 maxLineLength, blankLines, True, eol, backup) |
|
279 # always fix in place |
268 else: |
280 else: |
269 fixer = None |
281 fixer = None |
270 |
282 |
271 if not errors: |
283 if not errors: |
272 # avoid 'Encoding declaration in unicode string' exception on Python2 |
284 # avoid 'Encoding declaration in unicode string' exception on Python2 |