Created
June 13, 2017 13:45
-
-
Save terry90/2b90b297c814fa307487ea2981e0327a to your computer and use it in GitHub Desktop.
Rubocop autocorrection on Atom (simple version but works really good)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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