Exemplo n.º 1
0
def lint_js(document, move_cursor=False):
    """Check your js code with the jslint tool"""
    mark_iface = document.markInterface()
    clearMarksOfError(document, mark_iface)

    linter_name = SETTING_LINTER.choices[SETTING_LINTER.lookup()]  # lookup() gives index of choices
    get_linter(linter_name, partial(_lint, document, move_cursor, linter_name))
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def checkAll(doc=None, excludes=None, exclude_all=False):
    """Check the syntax, pep8 and pyflakes errors of the document"""
    python_utils_conf = kate.configuration.root.get('python_utils', {})
    if not (not doc or (is_mymetype_python(doc) and
                        not doc.isModified())):
        return
    is_called = not bool(doc)
    from python_checkers.parse_checker import parseCode
    excludes = excludes or []
    currentDoc = doc or kate.activeDocument()
    mark_iface = currentDoc.markInterface()
    clearMarksOfError(currentDoc, mark_iface)
    if not exclude_all:
        if not 'parseCode' in excludes and (is_called or python_utils_conf.get(_PARSECODE_CHECK_WHEN_SAVE, DEFAULT_PARSECODE_CHECK_WHEN_SAVE)):
            parseCode.f(currentDoc, refresh=False)
        if not 'checkPyflakes' in excludes and (is_called or python_utils_conf.get(_PYFLAKES_CHECK_WHEN_SAVE, DEFAULT_CHECK_PYFLAKES_WHEN_SAVE)):
            try:
                from python_checkers.pyflakes_checker import checkPyflakes
                checkPyflakes.f(currentDoc, refresh=False)
            except ImportError:
                pass
        if not 'checkPep8' in excludes and (is_called or python_utils_conf.get(_PEP8_CHECK_WHEN_SAVE, DEFAULT_CHECK_PEP8_WHEN_SAVE)):
            from python_checkers.pep8_checker import checkPep8
            checkPep8.f(currentDoc, refresh=False)
    if not doc and currentDoc.isModified() and not excludes:
        showError(i18n('You must save the file first'))
Exemplo n.º 4
0
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)