~ubuntu-branches/ubuntu/trusty/kate/trusty

« back to all changes in this revision

Viewing changes to addons/kate/pate/src/plugins/js_utils/jslint.py

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Rohan Garg, Jonathan Riddell, Philip Muškovac
  • Date: 2014-03-19 10:38:16 UTC
  • mfrom: (1.1.42)
  • Revision ID: package-import@ubuntu.com-20140319103816-f5b5t0m6hnwclzcn
Tags: 4:4.12.90-0ubuntu1
[ Rohan Garg ]
* Update install files

[ Jonathan Riddell ]
* New upstream beta release

[ Philip Muškovac ]
* Override license-problem-json-evil for js_lint.py as the file only
  references the evil file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
# Copyright (c) 2013 by Pablo Martín <goinnn@gmail.com> and
3
 
# Alejandro Blanco <alejandro.b.e@gmail.com>
4
 
#
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.
9
 
#
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.
14
 
#
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/>.
17
 
 
18
 
# This file originally was in this repository:
19
 
# <https://github.com/goinnn/Kate-plugins/blob/master/kate_plugins/jste_plugins/jslint_plugins.py>
20
 
 
21
 
 
22
 
import re
23
 
 
24
 
import kate
25
 
 
26
 
from PyKDE4.kdecore import i18n
27
 
 
28
 
from pyjslint import check_JSLint
29
 
 
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,
34
 
                                showErrors, showOk)
35
 
 
36
 
 
37
 
pattern = re.compile(r"Lint at line (\d+) character (\d+): (.*)")
38
 
 
39
 
 
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)
46
 
 
47
 
    if not (not currentDocument or (is_mymetype_js(currentDocument) and
48
 
                                    not currentDocument.isModified() and
49
 
                                    check_when_save)):
50
 
        return
51
 
    move_cursor = not currentDocument
52
 
    currentDocument = currentDocument or kate.activeDocument()
53
 
    mark_iface = currentDocument.markInterface()
54
 
    clearMarksOfError(currentDocument, mark_iface)
55
 
    hideOldPopUps()
56
 
    path = currentDocument.url().path()
57
 
    mark_key = '%s-jslint' % path
58
 
 
59
 
    text = currentDocument.text()
60
 
    errors = check_JSLint(text)
61
 
    errors_to_show = []
62
 
 
63
 
    # Prepare errors found for painting
64
 
    for error in errors:
65
 
        matches = pattern.search(error)
66
 
        if matches:
67
 
            errors_to_show.append({
68
 
                "message": matches.groups()[2],
69
 
                "line": int(matches.groups()[0]),
70
 
                "column": int(matches.groups()[1]) + 1,
71
 
            })
72
 
 
73
 
    if len(errors_to_show) == 0:
74
 
        showOk(i18n("JSLint Ok"))
75
 
        return
76
 
 
77
 
    showErrors(i18n('JSLint Errors:'),
78
 
               errors_to_show,
79
 
               mark_key, currentDocument,
80
 
               move_cursor=move_cursor)
81
 
 
82
 
 
83
 
def is_mymetype_js(doc, text_plain=False):
84
 
    mimetype = doc.mimeType()
85
 
    if mimetype == 'application/javascript':
86
 
        return True
87
 
    elif mimetype == 'text/plain' and text_plain:
88
 
        return True
89
 
    return False
90
 
 
91
 
 
92
 
@kate.init
93
 
@kate.viewCreated
94
 
def createSignalCheckDocument(view=None, *args, **kwargs):
95
 
    view = view or kate.activeView()
96
 
    doc = view.document()
97
 
    doc.modifiedChanged.connect(checkJslint.f)
98
 
 
99
 
# kate: space-indent on; indent-width 4;