rubocop-emacs icon indicating copy to clipboard operation
rubocop-emacs copied to clipboard

[Feature Request] More friendly auto-correct features

Open jimeh opened this issue 8 years ago • 3 comments

Update: I've achieved the goal of this feature request with a custom package called rubocopfmt. I will leave this issue open for others to see until @bbatsov feels it's appropriate to close it.


So due my lack of elisp skills, I have a badly hacked together set of tweaks to rubocop-mode that nearly makes the auto-correct stuff work the way I want: siren-rubocop.el

I'd love for something like these features to be available in rubocop-mode itself. The key features I'm after are:

  • Ability to automatically run auto-correct against current file on save, and have the local buffer update/revert instantly while retaining undo history.
  • Ability to trigger auto-correct for current file without the compile buffer opening. The compile buffer is annoying when auto-correcting on save, or if you manually want to quickly just auto-correct stuff and don't care for rubocop's output.
  • A way to turn auto-correct on save on/off. Maybe even with a minor-mode so it can easily be toggled on the fly rather than via a customizable variable.

As for my own hack, the only thing that's not working correctly is the instant revert/update when you run auto-correct. As far as I can figure I'm guessing compilation-start is async so the revert-buffer call fires after emacs has saved the file, but before rubocop has auto-corrected it.

jimeh avatar Jan 31 '16 19:01 jimeh

All of those things are trivial to implement, if only I had any free time these days... :-)

bbatsov avatar Jan 20 '17 09:01 bbatsov

Perhaps also an even more cautious auto-correct would be possible where only changes that involve lines that are changed in git would be auto-corrected. But perhaps that should be a suggestion for upstream rubocop instead, first.

yxhuvud avatar May 21 '18 09:05 yxhuvud

My hacked together solution from two years ago when I opened this issue has now evolved into a fully fledged package called rubocopfmt: https://github.com/jimeh/rubocopfmt.el

@yxhuvud While it's not as intelligent as only correcting lines which are modified in git, rubocopfmt does disable a few cops which causes confusion and annoyance in the context of a text editor with potentially work-in-progress code whenever you save.

@bbatsov I'd appreciate your thoughts on rubocopfmt. Specifically if you're cool with it being it's own package, or if you'd prefer it being merged into your rubocop package. Also as of 5 minutes ago I am considering renaming the project to rubocop-on-save so it's more in-line with what the package actually does now.

Edit: Nevermind on the name change, probably best to leave it as the fmt part is a nod to gofmt. Also I already have a PR against MELPA open to add the package :P

jimeh avatar May 21 '18 10:05 jimeh