-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJsValidate.py
39 lines (33 loc) · 1.15 KB
/
JsValidate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import re
SETTINGS_FILE = 'JSValidate.sublime-settings'
class JsvalidateCommand(sublime_plugin.TextCommand):
def run(self, edit):
settings = sublime.load_settings(SETTINGS_FILE)
cmd = settings.get('esvalidate', 'esvalidate')
filepath = self.view.file_name()
args = {
"cmd": [
cmd,
"--format=sublime",
filepath
],
'line_regex': settings.get('line_regex', r"(\d+),(\d+): (.*)$"),
'file_regex': settings.get('file_regex', r"esvalidate (.+)\]")
}
if sublime.platform() == "windows":
args['cmd'][0] += ".cmd"
elif sublime.platform() == "osx":
args['path'] = "/usr/local/share/npm/bin:/usr/local/bin:/opt/local/bin:$PATH"
self.view.window().run_command('exec', args)
class JsvalidateOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
settings = sublime.load_settings(SETTINGS_FILE)
if settings.get('run_on_save', False) == False:
return
if re.search(settings.get('filename_filter'), view.file_name()):
view.window().run_command("jsvalidate")
return