Beispiel #1
0
def checkJslint(currentDocument=None, refresh=True):
    if not (not currentDocument or (is_mymetype_js(currentDocument) and
                                    not currentDocument.isModified())):
        return
    if refresh:
        checkAll.f(currentDocument, ['checkJslint'],
                 exclude_all=not currentDocument)
    move_cursor = not currentDocument
    currentDocument = currentDocument or kate.activeDocument()
    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({
                "filename": path,
                "message": matches.groups()[2],
                "line": int(matches.groups()[0]),
                "column": int(matches.groups()[1]) + 1,
                })

    if len(errors_to_show) == 0:
        commons.showOk("JSLint Ok")
        return

    commons.showErrors('JSLint Errors:',
                       errors_to_show, mark_key, currentDocument,
                       move_cursor=move_cursor)
def checkPyflakes(currentDocument=None, refresh=True):
    if not commons.canCheckDocument(currentDocument):
        return
    if refresh:
        checkAll(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:
        commons.showOk("Pyflakes Ok")
        return

    # Prepare errors found for painting
    for error in errors:
        errors_to_show.append({
            "filename": path,
            "message": error.message % error.message_args,
            "line": error.lineno,
            })

    commons.showErrors('Pyflakes Errors:', errors_to_show,
                       mark_key, currentDocument,
                       move_cursor=move_cursor)
Beispiel #3
0
def checkPyflakes(currentDocument=None, refresh=True):
    if not commons.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:
        commons.showOk("Pyflakes Ok")
        return

    # Prepare errors found for painting
    for error in errors:
        errors_to_show.append({
            "filename": path,
            "message": error.message % error.message_args,
            "line": error.lineno,
        })

    commons.showErrors('Pyflakes Errors:',
                       errors_to_show,
                       mark_key,
                       currentDocument,
                       move_cursor=move_cursor)
Beispiel #4
0
def checkPep8(currentDocument=None, refresh=True):
    """Check the pep8 errors of the document"""
    if not commons.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:
        commons.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],
        })
    commons.showErrors('Pep8 Errors:',
                       errors_to_show,
                       mark_key,
                       currentDocument,
                       move_cursor=move_cursor)
Beispiel #5
0
def checkPep8(currentDocument=None, refresh=True):
    if not commons.canCheckDocument(currentDocument):
        return
    if refresh:
        checkAll(currentDocument, ['checkPep8'],
                 exclude_all=not currentDocument)
    move_cursor = not currentDocument
    currentDocument = currentDocument or kate.activeDocument()
    if currentDocument.isModified():
        kate.gui.popup('You must save the file first', 3,
                        icon='dialog-warning', minTextWidth=200)
        return
    path = unicode(currentDocument.url().path())
    mark_key = '%s-pep8' % unicode(currentDocument.url().path())
    # Check the file for errors with PEP8
    sys.argv = [path]
    pep8.process_options([path])
    checker = StoreErrorsChecker(path)
    checker.check_all()
    errors = checker.get_errors()

    if len(errors) == 0:
        commons.showOk('Pep8 Ok')
        return

    errors_to_show = []
    if IGNORE_PEP8_ERRORS:
        pep8.options.ignore.extend(IGNORE_PEP8_ERRORS)
        pep8.options.ignore = list(set(pep8.options.ignore))
    # Paint errors found
    for error in errors:
        if pep8.ignore_code(error[2]):
            continue
        errors_to_show.append({
            "line": error[0],
            "column": error[1] + 1,
            "filename": path,
            "message": error[3],
            })
    if errors_to_show:
        commons.showErrors('Pep8 Errors:', errors_to_show,
                            mark_key, currentDocument,
                            move_cursor=move_cursor)
    else:
        commons.showOk('Pep8 Ok')
Beispiel #6
0
def parseCode(doc=None, refresh=True):
    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['filename'] = e.filename
        error['text'] = e.text
        error['line'] = e.lineno
        showErrors('Parse code Errors:', [error], mark_key, doc,
                    move_cursor=move_cursor)
Beispiel #7
0
def parseCode(doc=None, refresh=True):
    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['filename'] = e.filename
        error['text'] = e.text
        error['line'] = e.lineno
        showErrors('Parse code Errors:', [error],
                   mark_key,
                   doc,
                   move_cursor=move_cursor)
Beispiel #8
0
def checkJslint(currentDocument=None, refresh=True):
    if not (not currentDocument or (is_mymetype_js(currentDocument)
                                    and not currentDocument.isModified())):
        return
    if refresh:
        checkAll.f(currentDocument, ['checkJslint'],
                   exclude_all=not currentDocument)
    move_cursor = not currentDocument
    currentDocument = currentDocument or kate.activeDocument()
    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({
                "filename": path,
                "message": matches.groups()[2],
                "line": int(matches.groups()[0]),
                "column": int(matches.groups()[1]) + 1,
            })

    if len(errors_to_show) == 0:
        commons.showOk("JSLint Ok")
        return

    commons.showErrors('JSLint Errors:',
                       errors_to_show,
                       mark_key,
                       currentDocument,
                       move_cursor=move_cursor)