16 # register the name checker |
16 # register the name checker |
17 pycodestyle.register_check(NamingStyleChecker, NamingStyleChecker.Codes) |
17 pycodestyle.register_check(NamingStyleChecker, NamingStyleChecker.Codes) |
18 |
18 |
19 from DocStyleChecker import DocStyleChecker |
19 from DocStyleChecker import DocStyleChecker |
20 from MiscellaneousChecker import MiscellaneousChecker |
20 from MiscellaneousChecker import MiscellaneousChecker |
21 from McCabeChecker import McCabeChecker |
21 # TODO: rename the following module |
|
22 from ComplexityChecker import ComplexityChecker |
22 |
23 |
23 |
24 |
24 def initService(): |
25 def initService(): |
25 """ |
26 """ |
26 Initialize the service and return the entry point. |
27 Initialize the service and return the entry point. |
186 @param filename source filename (string) |
187 @param filename source filename (string) |
187 @param source string containing the code to check (string) |
188 @param source string containing the code to check (string) |
188 @param args arguments used by the codeStyleCheck function (list of |
189 @param args arguments used by the codeStyleCheck function (list of |
189 excludeMessages (str), includeMessages (str), repeatMessages |
190 excludeMessages (str), includeMessages (str), repeatMessages |
190 (bool), fixCodes (str), noFixCodes (str), fixIssues (bool), |
191 (bool), fixCodes (str), noFixCodes (str), fixIssues (bool), |
191 maxLineLength (int), hangClosing (bool), docType (str), maximum |
192 maxLineLength (int), hangClosing (bool), docType (str), dictionary |
192 allowed code complexity (int), dictionary with arguments for the |
193 with arguments for the code complexity checker (dict), dictionary |
193 miscellaneous checker (dict), errors (list of str), eol (str), |
194 with arguments for the miscellaneous checker (dict), errors (list |
194 encoding (str), backup (bool)) |
195 of str), eol (str), encoding (str), backup (bool)) |
195 @return tuple of statistics (dict) and results (tuple for each found |
196 @return tuple of statistics (dict) and results (tuple for each found |
196 violation of style (tuple of lineno (int), position (int), text (str), |
197 violation of style (tuple of lineno (int), position (int), text (str), |
197 ignored (bool), fixed (bool), autofixing (bool), fixedMsg (str))) |
198 ignored (bool), fixed (bool), autofixing (bool), fixedMsg (str))) |
198 """ |
199 """ |
199 (excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes, |
200 (excludeMessages, includeMessages, repeatMessages, fixCodes, noFixCodes, |
200 fixIssues, maxLineLength, hangClosing, docType, maxComplexity, |
201 fixIssues, maxLineLength, hangClosing, docType, codeComplexityArgs, |
201 miscellaneousArgs, errors, eol, encoding, backup) = args |
202 miscellaneousArgs, errors, eol, encoding, backup) = args |
202 |
203 |
203 stats = {} |
204 stats = {} |
204 |
205 |
205 if fixIssues: |
206 if fixIssues: |
257 miscellaneousArgs) |
258 miscellaneousArgs) |
258 miscellaneousChecker.run() |
259 miscellaneousChecker.run() |
259 stats.update(miscellaneousChecker.counters) |
260 stats.update(miscellaneousChecker.counters) |
260 errors += miscellaneousChecker.errors |
261 errors += miscellaneousChecker.errors |
261 |
262 |
262 # check code complexity iaw. McCabe |
263 # check code complexity |
263 mccabeChecker = McCabeChecker( |
264 complexityChecker = ComplexityChecker( |
264 source, filename, select, ignore, maxComplexity) |
265 source, filename, select, ignore, codeComplexityArgs) |
265 mccabeChecker.run() |
266 complexityChecker.run() |
266 stats.update(mccabeChecker.counters) |
267 stats.update(complexityChecker.counters) |
267 errors += mccabeChecker.errors |
268 errors += complexityChecker.errors |
268 |
269 |
269 errorsDict = {} |
270 errorsDict = {} |
270 for fname, lineno, position, text in errors: |
271 for fname, lineno, position, text in errors: |
271 if lineno > len(source): |
272 if lineno > len(source): |
272 lineno = len(source) |
273 lineno = len(source) |