Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add fixjsstyle command.

  • Loading branch information...
commit 5c2fdd4fa40b4cd1eae477e8d50ddc1b7be15b1d 1 parent dcce036
@fbzhong authored
View
5 Default (Linux).sublime-keymap
@@ -3,5 +3,10 @@
"keys": ["ctrl+shift+j"],
"__doc__": "Run Google Closure Linter",
"command": "closure_linter"
+ },
+ {
+ "keys": ["ctrl+alt+shift+j"],
+ "__doc__": "Fix JavaScript Style",
+ "command": "fix_js_style"
}
]
View
5 Default (OSX).sublime-keymap
@@ -3,5 +3,10 @@
"keys": ["ctrl+shift+j"],
"__doc__": "Run Google Closure Linter",
"command": "closure_linter"
+ },
+ {
+ "keys": ["ctrl+alt+shift+j"],
+ "__doc__": "Fix JavaScript Style",
+ "command": "fix_js_style"
}
]
View
5 Default (Windows).sublime-keymap
@@ -3,5 +3,10 @@
"keys": ["ctrl+shift+j"],
"__doc__": "Run Google Closure Linter",
"command": "closure_linter"
+ },
+ {
+ "keys": ["ctrl+alt+shift+j"],
+ "__doc__": "Fix JavaScript Style",
+ "command": "fix_js_style"
}
]
View
4 Default.sublime-commands
@@ -8,6 +8,10 @@
"command": "show_closure_linter_result"
},
{
+ "caption": "Closure Linter: Fix JavaScript Style",
+ "command": "fix_js_style"
+ },
+ {
"caption": "Preferences: Closure Linter Settings – Default",
"command": "open_file", "args":
{
View
4 Main.sublime-menu
@@ -13,6 +13,10 @@
"command": "closure_linter"
},
{
+ "caption": "Fix JavaScript Style",
+ "command": "fix_js_style"
+ },
+ {
"caption": "Show Closure Linter Result",
"command": "show_closure_linter_result"
}
View
88 gjslint.py
@@ -94,6 +94,94 @@ def proc_terminated(self, proc):
ClosureLinterEventListener.disabled = False
+class FixJsStyleCommand(sublime_plugin.WindowCommand):
+ def run(self):
+ file_path = self.window.active_view().file_name()
+ file_name = os.path.basename(file_path)
+
+ self.buffered_data = ''
+ self.file_path = file_path
+ self.file_name = file_name
+ self.is_running = True
+ self.tests_panel_showed = False
+ self.file_view = self.window.active_view()
+
+ self.init_tests_panel()
+
+ if file_name.endswith('.js') == False:
+ self.append_data(None, "fixjslint can only be used for JavaScript file.", True)
+ return
+
+ # save file.
+ self.file_view.run_command('save')
+
+ s = sublime.load_settings(SETTINGS_FILE)
+ cmd = s.get('fixjsstyle_path', 'fixjsstyle') + ' ' + s.get('fixjsstyle_flags', '') + ' "' + file_path + '"'
+
+ if s.get('debug', False) == True:
+ print "DEBUG: " + str(cmd)
+
+ AsyncProcess(cmd, self)
+ StatusProcess('Starting Fix Javascript Style 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)
+ 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 + ' fixjsstyle done!'
+ else:
+ msg = ''
+ self.append_data(proc, msg, True)
+
+ ClosureLinterEventListener.disabled = False
class ClosureLinterEventListener(sublime_plugin.EventListener):
"""jslint event"""
View
6 sublime-closure-linter.sublime-settings
@@ -5,6 +5,12 @@
// Flags pass to gjslint.
"gjslint_flags": "",
+ // Path to the fixjsstyle.
+ "fixjsstyle_path": "fixjsstyle",
+
+ // Flags pass to fixjsstyle.
+ "fixjsstyle_flags": "",
+
// debug flag.
"debug": false
}
Please sign in to comment.
Something went wrong with that request. Please try again.