Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically runs Rubocop on save #29

Merged
merged 2 commits into from
Mar 26, 2019

Conversation

dcluna
Copy link
Contributor

@dcluna dcluna commented Jul 25, 2018

Does exactly what it says on the tin.

Addresses #10, and probably #21 too.

rubocop.el Outdated
:group 'rubocop
(when rubocop-autocorrect-on-save
(if rubocop-mode
(add-hook 'before-save-hook 'rubocop-autocorrect-current-file-silent nil t)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if there was some function added to the hook that checks the value of the defcustom instead. That way if you toggle the defcustom you won't have to restart rubocop-mode.

rubocop.el Outdated
@@ -182,6 +187,9 @@ Alternatively prompt user for directory."
(interactive)
(rubocop--file-command rubocop-autocorrect-command))

(defun rubocop-autocorrect-current-file-silent ()
(save-window-excursion (rubocop-autocorrect-current-file)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to add some option to the existing command to correct silently.

@sadhu89
Copy link

sadhu89 commented Nov 21, 2018

This is great! Could I make it work with --safe-autocorrect?

@sadhu89
Copy link

sadhu89 commented Nov 22, 2018

I have been using these a couple of days and I love it. Is there a way I can avoid it gets executed when super-save saves the file automatically?

@dcluna
Copy link
Contributor Author

dcluna commented Dec 6, 2018

@sadhu89 I was thinking you could customize this function in super-save, maybe using one of the advices defined there to temporarily set the defcustom defined here to nil. WDYT?

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 26, 2019

I forgot to merge this. Please rebase it and ping me afterwards, so we can wrap it up.

@dcluna dcluna force-pushed the rubocop-auto-correct-before-save branch from dcfa512 to c9ff017 Compare March 26, 2019 14:15
@dcluna
Copy link
Contributor Author

dcluna commented Mar 26, 2019

@bbatsov ping

@bbatsov bbatsov merged commit 03bf155 into rubocop:master Mar 26, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 26, 2019

Thanks!

@dcluna dcluna deleted the rubocop-auto-correct-before-save branch March 26, 2019 14:28
@grauschnabel
Copy link

Could you make a statement in the README.md also? I always get
Compilation exited abnormally with code 127
but don't know which settings are wrong.

@dcluna
Copy link
Contributor Author

dcluna commented Apr 10, 2019

@grauschnabel If you run rubocop-autocorrect-current-file interactively, does it work?

I recommend doing bundle install after ensuring rubocop is in the project's Gemfile or setting rubocop-prefer-system-executable to t if that's what you use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants