Closed ProGM closed 8 years ago
It doesn't currently exist but it would be a nice feature. I'm not sure if the linter framework supports having commands. On Apr 3, 2015 5:31 AM, "Piero Dotti" notifications@github.com wrote:
This plugin works very well, but there is no way to call the rubocop autocorrect function, isn't it?
If so, do you plan to add it?
— Reply to this email directly or view it on GitHub https://github.com/SublimeLinter/SublimeLinter-rubocop/issues/19.
Uhm... Probably not. What about adding it externally from SublimeLinter?
Was hoping this was as simple as
"rubocop": {
"@disable": false,
"args": [
"--auto-correct"
],
"excludes": []
},
in the SublimeLinter - User Settings, but unfortunately adding this only displays the text [corrected] on lines that rubocop would be able to correct. It doesn't actually correct them. This might require the creation of another plugin.
@ProGM The Sublime_Rubocop plugin allows for autocorrect functionality from the sublime command menu. https://github.com/pderichs/sublime_rubocop. Have just tried it and it works pretty well. Add this to the RuboCop.sublime_settings to allow Sublime linter to still manage file linting.
{
"mark_issues_in_view": false,
}
@joshmfrankel Thank you, I'm trying it :)
That's great!
Another way would be just call rubocop -a
on an editable file. To run a shell command from ST3 I’ve used Shell Exec package and added the following command to Default.sublime-commands
file under Packages
folder:
[
{
"caption": "RuboCop: autocorrect",
"command": "shell_exec_run",
"args": {
"command": "rubocop -a ${file}"
}
}
]
The above command will then appear in the Command Palette.
For Guard users I've found a lot of success with using the guard-rubocop plugin to automatically run fixing on save. Simple as:
guard :rubocop, all_on_start: false, cli: "--fix" do
watch(%r{.+\.rb$})
end
Plugin for running rubocop on save:
import sublime
import sublime_plugin
import os
import subprocess
class RubyFormatOnSave(sublime_plugin.EventListener):
def on_post_save_async(self, view):
filename = view.file_name()
if view.match_selector(0, "source.ruby"):
subprocess.call(
["rubocop", "-a", filename],
cwd=os.path.dirname(filename)
)
Just copy it over your Packages/User
folder.
@fnando I created a new file with the code from above and put in my Packages/User
folder but saving doesn't seem to cause the autocorrect. Is there something else I need to do to enable it?
@drewB I extracted this script into a plugin a while ago: https://github.com/fnando/sublime-rubocop-formatter
Thanks will check it out.
@fnando the link you posted above is broken, but your repos look cool. https://github.com/fnando & https://sublime.fnando.com/
I tried a couple, but installation isn't quite working. Can you help? Am interested in:
This plugin works very well, but there is no way to call the
rubocop
autocorrect function, isn't it?If so, do you plan to add it?