Skip to content

Instantly share code, notes, and snippets.

@terry90
Created June 13, 2017 13:45
Show Gist options
  • Save terry90/2b90b297c814fa307487ea2981e0327a to your computer and use it in GitHub Desktop.
Save terry90/2b90b297c814fa307487ea2981e0327a to your computer and use it in GitHub Desktop.
Rubocop autocorrection on Atom (simple version but works really good)
# Add this to init.coffee in ~/.atom/
{BufferedProcess} = require 'atom'
rubocopOutput = (data) ->
if (data.stderr)
atom.notifications.addError(data.stderr)
return
if (data.summary.offense_count == 0)
atom.notifications.addSuccess('No offenses found')
for file in data.files
for offense in file.offenses
if offense.corrected
atom.notifications.addSuccess(
"Fixed: #{offense.location.line}:#{offense.location.column}",
{ detail: "#{offense.message}" }
)
else
atom.notifications.addWarning(
"#{offense.location.line}:#{offense.location.column}",
{ detail: "#{offense.message}" }
)
atom.workspace.observeTextEditors (editor) ->
editor.onDidSave ->
stdout = (output) =>
rubocopOutput(JSON.parse(output))
editor.getBuffer().reload()
stderr = (output) =>
rubocopOutput({'stderr': "#{output}"})
srcFile = editor.getPath()
command = 'rubocop'
args = ['-a', '--format', 'json', srcFile]
new BufferedProcess({ command, args, stdout, stderr })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment