def checkPyflakes(currentDocument=None, refresh=True): """Check the pyflakes errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPyflakes'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() path = currentDocument.url().path() mark_key = '%s-pyflakes' % path text = currentDocument.text() errors = pyflakes(text, path) errors_to_show = [] if len(errors) == 0: showOk(i18n("Pyflakes Ok")) return # Prepare errors found for painting for error in errors: error_to_show = { "message": error.message % error.message_args, "line": error.lineno, } if getattr(error, 'col', None) is not None: error_to_show['column'] = error.col + 1 errors_to_show.append(error_to_show) showErrors(i18n('Pyflakes Errors:'), errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def _lint(document, move_cursor, linter_name, linter): """extracted part of lint_js that has to be called after the linter is ready""" ok = linter(document.text(), {}) if ok: showOk(i18nc('@info:status', '<application>%1</application> OK', linter_name)) return errors = [error for error in linter['errors'] if error] # sometimes None # Prepare errors found for painting for error in errors: error['message'] = error.pop('reason') # rename since showErrors has 'message' hardcoded error.pop('raw', None) # Only reason, line, and character are always there error.pop('a', None) error.pop('b', None) error.pop('c', None) error.pop('d', None) mark_key = '{}-{}'.format(document.url().path(), linter_name) showErrors(i18nc('@info:status', '<application>%1</application> Errors:', linter_name), errors, mark_key, document, key_column='character', move_cursor=move_cursor)
def checkPyflakes(currentDocument=None, refresh=True): """Check the pyflakes errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPyflakes'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() path = unicode(currentDocument.url().path()) mark_key = '%s-pyflakes' % path text = unicode(currentDocument.text()) errors = pyflakes(text.encode('utf-8', 'ignore'), path) errors_to_show = [] if len(errors) == 0: showOk("Pyflakes Ok") return # Prepare errors found for painting for error in errors: errors_to_show.append({ "message": error.message % error.message_args, "line": error.lineno, }) showErrors('Pyflakes Errors:', errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def checkJslint(currentDocument=None): """Check your js code with the jslint tool""" if not (not currentDocument or (is_mymetype_js(currentDocument) and not currentDocument.isModified())): return move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() mark_iface = currentDocument.markInterface() clearMarksOfError(currentDocument, mark_iface) hideOldPopUps() path = unicode(currentDocument.url().path()) mark_key = '%s-jslint' % path text = unicode(currentDocument.text()) errors = check_JSLint(text.encode('utf-8', 'ignore')) errors_to_show = [] # Prepare errors found for painting for error in errors: matches = pattern.search(error) if matches: errors_to_show.append({ "message": matches.groups()[2], "line": int(matches.groups()[0]), "column": int(matches.groups()[1]) + 1, }) if len(errors_to_show) == 0: showOk("JSLint Ok") return showErrors('JSLint Errors:', errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def checkPep8(currentDocument=None, refresh=True): """Check the pep8 errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPep8'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() if currentDocument.isModified(): saveFirst() return path = currentDocument.url().path() if not path: saveFirst() return mark_key = '%s-pep8' % currentDocument.url().path() # Check the file for errors with PEP8 sys.argv = [path] pep8.process_options([path]) python_utils_conf = kate.configuration.root.get('python_utils', {}) ignore_pep8_errors = python_utils_conf.get(_IGNORE_PEP8_ERRORS, DEFAULT_IGNORE_PEP8_ERRORS) if ignore_pep8_errors: ignore_pep8_errors = ignore_pep8_errors.split(",") else: ignore_pep8_errors = [] if pep8.__version__ in OLD_PEP8_VERSIONS: checker = StoreErrorsChecker(path) pep8.options.ignore = ignore_pep8_errors checker.check_all() errors = checker.get_errors() else: checker = pep8.Checker(path, reporter=KateReport, ignore=ignore_pep8_errors) checker.check_all() errors = checker.report.get_errors() if len(errors) == 0: showOk(i18n('Pep8 Ok')) return errors_to_show = [] # Paint errors found for error in errors: errors_to_show.append({ "line": error[0], "column": error[1] + 1, "message": error[3], }) showErrors(i18n('Pep8 Errors:'), errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def checkPep8(currentDocument=None, refresh=True): """Check the pep8 errors of the document""" if not canCheckDocument(currentDocument): return if refresh: checkAll.f(currentDocument, ['checkPep8'], exclude_all=not currentDocument) move_cursor = not currentDocument currentDocument = currentDocument or kate.activeDocument() if currentDocument.isModified(): saveFirst() return path = unicode(currentDocument.url().path()) if not path: saveFirst() return mark_key = '%s-pep8' % unicode(currentDocument.url().path()) # Check the file for errors with PEP8 sys.argv = [path] pep8.process_options([path]) if pep8.__version__ in OLD_PEP8_VERSIONS: checker = StoreErrorsChecker(path) pep8.options.ignore = IGNORE_PEP8_ERRORS checker.check_all() errors = checker.get_errors() else: checker = pep8.Checker(path, reporter=KateReport, ignore=IGNORE_PEP8_ERRORS) checker.check_all() errors = checker.report.get_errors() if len(errors) == 0: showOk('Pep8 Ok') return errors_to_show = [] # Paint errors found for error in errors: errors_to_show.append({ "line": error[0], "column": error[1] + 1, "message": error[3], }) showErrors('Pep8 Errors:', errors_to_show, mark_key, currentDocument, move_cursor=move_cursor)
def parseCode(doc=None, refresh=True): """Check the syntax errors of the document""" if not canCheckDocument(doc): return if refresh: checkAll.f(doc, ['parseCode'], exclude_all=not doc) move_cursor = not doc doc = doc or kate.activeDocument() text = doc.text() text = text.encode('utf-8', 'ignore') mark_key = '%s-parse-python' % doc.url().path() try: parse(text) showOk(i18n('Parse code Ok')) except SyntaxError as e: error = {} error['text'] = e.text error['line'] = e.lineno showErrors(i18n('Parse code Errors:'), [error], mark_key, doc, move_cursor=move_cursor)
def parseCode(doc=None, refresh=True): """Check the syntax errors of the document""" if not canCheckDocument(doc): return if refresh: checkAll.f(doc, ['parseCode'], exclude_all=not doc) move_cursor = not doc doc = doc or kate.activeDocument() text = unicode(doc.text()) text = text.encode('utf-8', 'ignore') mark_key = '%s-parse-python' % unicode(doc.url().path()) try: compiler.parse(text) showOk('Parse code Ok') except SyntaxError, e: error = {} error['text'] = e.text error['line'] = e.lineno showErrors('Parse code Errors:', [error], mark_key, doc, move_cursor=move_cursor)