1
# -*- coding: utf-8 -*-
2
# Copyright (c) 2013 by Pablo Martín <goinnn@gmail.com> and
3
# Alejandro Blanco <alejandro.b.e@gmail.com>
5
# This software is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# This software is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public License
16
# along with this software. If not, see <http://www.gnu.org/licenses/>.
18
# This file originally was in this repository:
19
# <https://github.com/goinnn/Kate-plugins/blob/master/kate_plugins/jste_plugins/jslint_plugins.py>
26
from PyKDE4.kdecore import i18n
28
from pyjslint import check_JSLint
30
from js_settings import (KATE_ACTIONS,
31
_JSLINT_CHECK_WHEN_SAVE,
32
DEFAULT_CHECK_JSLINT_WHEN_SAVE)
33
from libkatepate.errors import (clearMarksOfError, hideOldPopUps,
37
pattern = re.compile(r"Lint at line (\d+) character (\d+): (.*)")
40
@kate.action(**KATE_ACTIONS['checkJslint'])
41
def checkJslint(currentDocument=None):
42
"""Check your js code with the jslint tool"""
43
js_utils_conf = kate.configuration.root.get('js_utils', {})
44
check_when_save = js_utils_conf.get(_JSLINT_CHECK_WHEN_SAVE,
45
DEFAULT_CHECK_JSLINT_WHEN_SAVE)
47
if not (not currentDocument or (is_mymetype_js(currentDocument) and
48
not currentDocument.isModified() and
51
move_cursor = not currentDocument
52
currentDocument = currentDocument or kate.activeDocument()
53
mark_iface = currentDocument.markInterface()
54
clearMarksOfError(currentDocument, mark_iface)
56
path = currentDocument.url().path()
57
mark_key = '%s-jslint' % path
59
text = currentDocument.text()
60
errors = check_JSLint(text)
63
# Prepare errors found for painting
65
matches = pattern.search(error)
67
errors_to_show.append({
68
"message": matches.groups()[2],
69
"line": int(matches.groups()[0]),
70
"column": int(matches.groups()[1]) + 1,
73
if len(errors_to_show) == 0:
74
showOk(i18n("JSLint Ok"))
77
showErrors(i18n('JSLint Errors:'),
79
mark_key, currentDocument,
80
move_cursor=move_cursor)
83
def is_mymetype_js(doc, text_plain=False):
84
mimetype = doc.mimeType()
85
if mimetype == 'application/javascript':
87
elif mimetype == 'text/plain' and text_plain:
94
def createSignalCheckDocument(view=None, *args, **kwargs):
95
view = view or kate.activeView()
97
doc.modifiedChanged.connect(checkJslint.f)
99
# kate: space-indent on; indent-width 4;