Skip to content

Instantly share code, notes, and snippets.

@allizon
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allizon/9de3a875be503feeb45f to your computer and use it in GitHub Desktop.
Save allizon/9de3a875be503feeb45f to your computer and use it in GitHub Desktop.
Sublime Text 3 EventListener to run Ruby files through Rubocop on save. Save to your Packages/User directory.
import sublime, sublime_plugin
import os
import subprocess
class RubocopCommand(sublime_plugin.EventListener):
# Replace this with the path to your Rubocop bin (obviously)
RUBOCOP_BIN = '/Users/alholt/.rbenv/shims/rubocop'
def on_post_save_async(self, view):
if view.file_name().endswith('rb'):
self.set_status('Running through Rubocop...')
cmd_a = [ self.RUBOCOP_BIN + ' --format simple ' + view.file_name() ]
p = subprocess.Popen(cmd_a, stdout = subprocess.PIPE,
stderr = subprocess.STDOUT, shell = True)
if p.stdout is not None:
self.process_results(p.stdout.readlines())
else:
self.set_status('No Rubocop issues found.')
def process_results(self, data):
sublime.status_message(data[-1].decode('utf-8'))
for row in data:
row = row.decode('utf-8')
if len(row) > 1:
print(row)
def set_status(self, message):
print(message)
sublime.status_message(message)
@allizon
Copy link
Author

allizon commented Sep 4, 2014

OK, cleaned up a bit. Still open to enhancements from others!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment