Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make RubyMine autocorrect with Rubocop on every save

Is there a way to get Rubocop to format my code every time I save in RubyMine? This was a feature in VSCode, which you were able to set via "editor.formatOnSave": true, in the settings.json. Is there a similar "autocorrect on save" possibility for Rubymine?

like image 607
bgcode Avatar asked Jan 07 '21 02:01

bgcode


People also ask

How do I run rubocop in RubyMine?

From the main menu, go to Code | Analyze Code | Run Inspection by Name Ctrl+Alt+Shift+I. In the popup, find RuboCop and press Enter. In the Run 'RuboCop' dialog, specify the scope of files that you want to analyze. If necessary, enable Use 'standard' gem. Click OK. Wait until RubyMine analyzes your project.

Why isn't my rubocop inspection report showing up in RubyMine?

.rubocop.yml. RubyMine takes into account all settings specified in the .rubocop.yml file. For example, if you disable some checks for a specified cop department, the editor will not show corresponding offenses. Moreover, these offenses won't be shown in the RuboCop inspection report.

Does rubocop support auto-correcting?

See Auto-correct for more details. RuboCop comes with a preconfigured set of rules for each of its cops, based on the Ruby Style Guide . Depending on your project, you may wish to reconfigure a cop, tell to ignore certain files, or disable it altogether.

How do I add a shortcut to a rubocop action?

(Optional) Assign a shortcut for the created action. In the Settings/Preferences dialog Ctrl+Alt+S, select Keymap, find the Fix Layout action under the RuboCop node and specify a shortcut. To run the created RuboCop action, go to the Tools main menu or use the context menu of a file.


2 Answers

As of RubyMine 2021.3 this is now explicitly supported as a feature:

https://blog.jetbrains.com/ruby/2021/10/rubymine-2021-3-eap5/#run_rubocop_on_save

like image 69
Douglas Greenshields Avatar answered Oct 22 '22 01:10

Douglas Greenshields


Unfortunately at the moment it's not possible so please add your votes to the corresponding feature requests:

https://youtrack.jetbrains.com/issue/RUBY-19589

https://youtrack.jetbrains.com/issue/RUBY-27248

like image 21
Olivia Avatar answered Oct 22 '22 00:10

Olivia