Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add code to repo.

  • Loading branch information...
commit 97c77e39c5cbb475a0153bfe14c36773b8ce98d4 0 parents
@fbzhong authored
3  .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+*.pyc
+
7 Default (Linux).sublime-keymap
@@ -0,0 +1,7 @@
+[
+ {
+ "keys": ["ctrl+shift+j"],
+ "__doc__": "Run Google Closure Linter",
+ "command": "closure_linter"
+ }
+]
7 Default (OSX).sublime-keymap
@@ -0,0 +1,7 @@
+[
+ {
+ "keys": ["ctrl+shift+j"],
+ "__doc__": "Run Google Closure Linter",
+ "command": "closure_linter"
+ }
+]
7 Default (Windows).sublime-keymap
@@ -0,0 +1,7 @@
+[
+ {
+ "keys": ["ctrl+shift+j"],
+ "__doc__": "Run Google Closure Linter",
+ "command": "closure_linter"
+ }
+]
10 Default.sublime-commands
@@ -0,0 +1,10 @@
+[
+ {
+ "caption": "Closure Linter: Run Closure Linter",
+ "command": "closure_linter"
+ },
+ {
+ "caption": "Closure Linter: Show Closure Linter Result",
+ "command": "show_closure_linter_result"
+ }
+]
8 LICENSE
@@ -0,0 +1,8 @@
+Copyright (c) 2011, Robin Zhong (fbzhong@gmail.com)
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 Main.sublime-menu
@@ -0,0 +1,23 @@
+[
+ {
+ "id": "tools",
+ "children":
+ [
+ {
+ "caption": "Lint",
+ "id": "lint",
+ "children":
+ [
+ {
+ "caption": "Run Closure Linter",
+ "command": "closure_linter"
+ },
+ {
+ "caption": "Show Closure Linter Result",
+ "command": "show_closure_linter_result"
+ }
+ ]
+ }
+ ]
+ }
+]
67 README.md
@@ -0,0 +1,67 @@
+Google Closure Linter support for Sublime Text 2
+========================
+
+Sublime Text 2 (http://www.sublimetext.com/2) is a sophisticated text editor for code, html and prose. You'll love the slick user interface and extraordinary features.
+
+The Closure Linter (http://code.google.com/p/closure-linter/) enforces the guidelines set by the [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml). The linter handles style issues so that you can focus on the code.
+
+This project provide a plugin to add Google Closure Linter support for Sublime Text 2.
+
+Features
+-------------
+
+- Closure Linter: Run Closure Linter (ctrl+shift+j)
+
+- Closure Linter: Show Closure Linter Result
+
+- Highlight error line by click on the result view
+
+- Cross platform: support Windows, Linux and Mac OS X
+
+Requirements
+-------------
+
+- Google Closure Linter http://code.google.com/p/closure-linter/
+
+Installation
+-------------
+
+- Using Package Control http://wbond.net/sublime_packages/package_control
+ > Add Repository: https://github.com/fbzhong/sublime-closure-linter
+
+- Download and extract to Sublime Text 2 Packages folder
+ > Windows: %APPDATA%\Sublime Text 2\Packages
+ > Mac OS X: ~/Library/Application Support/Sublime Text 2/Packages
+ > Linux: ~/.config/sublime-text-2/Packages
+
+How to use?
+-------------
+
+- Using the Command Palette (Windows and Linux: Ctrl+Shift+P, OSX: Command+Shift+P) then search for:
+
+ - Closure Linter: Run Closure Linter (ctrl+shift+j)
+ - Closure Linter: Show Closure Linter Result
+
+- Find them in Tools menu:
+ - Tools -> Lint -> Run Closure Linter
+ - Tools -> Lint -> Show Closure Linter Result
+
+Open up a .js file and hit ctrl+shift+j to run Closure Linter. An new output panel will appear giving you the Closure Linter results:
+
+Screenshots
+-------------
+
+![](https://github.com/fbzhong/sublime-closure-linter/raw/master/images/screenshot.png)
+
+License
+-------------
+
+Copyright (c) 2011, Robin Zhong (fbzhong@gmail.com)
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 asyncprocess.py
@@ -0,0 +1,48 @@
+import os
+import thread
+import subprocess
+import functools
+import time
+import sublime
+
+class AsyncProcess(object):
+ def __init__(self, cmd, listener):
+ self.cmd = cmd
+ self.listener = listener
+ #print "DEBUG_EXEC: " + str(self.cmd)
+ self.proc = subprocess.Popen([self.cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ if self.proc.stdout:
+ thread.start_new_thread(self.read_stdout, ())
+
+ if self.proc.stderr:
+ thread.start_new_thread(self.read_stderr, ())
+
+ thread.start_new_thread(self.poll, ())
+
+ def poll(self):
+ while True:
+ if self.proc.poll() != None:
+ sublime.set_timeout(functools.partial(self.listener.proc_terminated, self.proc), 0)
+ break
+ time.sleep(0.1)
+
+ def read_stdout(self):
+ while True:
+ data = os.read(self.proc.stdout.fileno(), 2**15)
+ if data != "":
+ sublime.set_timeout(functools.partial(self.listener.append_data, self.proc, data), 0)
+ else:
+ self.proc.stdout.close()
+ self.listener.is_running = False
+ break
+
+ def read_stderr(self):
+ while True:
+ data = os.read(self.proc.stderr.fileno(), 2**15)
+ if data != "":
+ sublime.set_timeout(functools.partial(self.listener.append_data, self.proc, data), 0)
+ else:
+ self.proc.stderr.close()
+ self.listener.is_running = False
+ break
147 gjslint.py
@@ -0,0 +1,147 @@
+import os
+import re
+import sublime
+import sublime_plugin
+from statusprocess import *
+from asyncprocess import *
+
+RESULT_VIEW_NAME = 'gjslint_result_view'
+
+class ShowClosureLinterResultCommand(sublime_plugin.WindowCommand):
+ """show closure linter result"""
+ def run(self):
+ self.window.run_command("show_panel", {"panel": "output."+RESULT_VIEW_NAME})
+
+class ClosureLinterCommand(sublime_plugin.WindowCommand):
+ def run(self):
+ file_path = self.window.active_view().file_name()
+ file_name = os.path.basename(file_path)
+ cmd = '/usr/local/bin/gjslint "' + file_path + '"'
+
+ print "DEBUG: " + str(cmd)
+ self.buffered_data = ''
+ self.file_path = file_path
+ self.file_name = file_name
+ self.is_running = True
+ self.tests_panel_showed = False
+
+ self.init_tests_panel()
+
+ AsyncProcess(cmd, self)
+ StatusProcess('Starting Closure Lint for file ' + file_name, self)
+
+ ClosureLinterEventListener.disabled = True
+
+ def init_tests_panel(self):
+ if not hasattr(self, 'output_view'):
+ self.output_view = self.window.get_output_panel(RESULT_VIEW_NAME)
+ self.output_view.set_name(RESULT_VIEW_NAME)
+ self.clear_test_view()
+ self.output_view.settings().set("file_path", self.file_path)
+
+ def show_tests_panel(self):
+ if self.tests_panel_showed:
+ return
+ self.window.run_command("show_panel", {"panel": "output."+RESULT_VIEW_NAME})
+ self.tests_panel_showed = True
+
+ def clear_test_view(self):
+ self.output_view.set_read_only(False)
+ edit = self.output_view.begin_edit()
+ self.output_view.erase(edit, sublime.Region(0, self.output_view.size()))
+ self.output_view.end_edit(edit)
+ self.output_view.set_read_only(True)
+
+ def append_data(self, proc, data, flush=False):
+ self.buffered_data = self.buffered_data + data.decode("utf-8")
+ str = self.buffered_data.replace(self.file_path, self.file_name).replace('\r\n', '\n').replace('\r', '\n')
+
+ if flush == False:
+ rsep_pos = str.rfind('\n')
+ if rsep_pos == -1:
+ # not found full line.
+ return
+ self.buffered_data = str[rsep_pos+1:]
+ str = str[:rsep_pos+1]
+
+ self.show_tests_panel()
+ selection_was_at_end = (len(self.output_view.sel()) == 1 and self.output_view.sel()[0] == sublime.Region(self.output_view.size()))
+ self.output_view.set_read_only(False)
+ edit = self.output_view.begin_edit()
+ self.output_view.insert(edit, self.output_view.size(), str.strip())
+ if selection_was_at_end:
+ self.output_view.show(self.output_view.size())
+ self.output_view.end_edit(edit)
+ self.output_view.set_read_only(True)
+
+ if flush:
+ self.output_view.run_command("goto_line", {"line": 1})
+
+ def update_status(self, msg, progress):
+ sublime.status_message(msg + " " + progress)
+
+ def proc_terminated(self, proc):
+ if proc.returncode == 0:
+ msg = self.file_name + ' lint free!'
+ else:
+ msg = ''
+ self.append_data(proc, msg, True)
+
+ ClosureLinterEventListener.disabled = False
+
+
+class ClosureLinterEventListener(sublime_plugin.EventListener):
+ """jslint event"""
+ disabled = False
+ def __init__(self):
+ self.previous_resion = None
+ self.file_view = None
+
+ def on_deactivated(self, view):
+ if view.name() != RESULT_VIEW_NAME:
+ return
+ self.previous_resion = None
+ self.file_view.erase_regions(RESULT_VIEW_NAME)
+
+ def on_selection_modified(self, view):
+ if ClosureLinterEventListener.disabled:
+ return
+ if view.name() != RESULT_VIEW_NAME:
+ return
+ region = view.line(view.sel()[0])
+
+ # make sure call once.
+ if self.previous_resion == region:
+ return
+ self.previous_resion = region
+
+ # extract line from jslint result.
+ m = re.match('^Line (\d+), E:(\d+):', view.substr(region))
+ if m == None:
+ return
+ line = int(m.group(1))
+ col = int(m.group(2))
+
+ # hightligh view line.
+ view.add_regions(RESULT_VIEW_NAME, [region], "comment")
+
+ # find the file view.
+ file_path = view.settings().get('file_path')
+ window = sublime.active_window()
+ file_view = None
+ for v in window.views():
+ if v.file_name() == file_path:
+ file_view = v
+ break
+ if file_view == None:
+ return
+
+ self.file_view = file_view
+ window.focus_view(file_view)
+ file_view.run_command("goto_line", {"line": line})
+ file_region = file_view.line(file_view.sel()[0])
+
+ # highlight file_view line
+ file_view.add_regions(RESULT_VIEW_NAME, [file_region], "string")
+
+
BIN  images/screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 package-metadata.json
@@ -0,0 +1,5 @@
+{
+ "version": "0.1",
+ "url": "https://github.com/fbzhong/sublime-closure-linter",
+ "description": "Google Closure Linter for Sublime Text 2"
+}
22 statusprocess.py
@@ -0,0 +1,22 @@
+import thread
+import functools
+import time
+import sublime
+
+class StatusProcess(object):
+ def __init__(self, msg, listener):
+ self.msg = msg
+ self.listener = listener
+ thread.start_new_thread(self.run_thread, ())
+
+ def run_thread(self):
+ progress = ""
+ while True:
+ if self.listener.is_running:
+ if len(progress) >= 10:
+ progress = ""
+ progress += "."
+ sublime.set_timeout(functools.partial(self.listener.update_status, self.msg, progress), 0)
+ time.sleep(0.1)
+ else:
+ break
Please sign in to comment.
Something went wrong with that request. Please try again.