Find & Fix all RuboCop Inspections in one go

Hi all,

The fresh RubyMine 2017.3.1 RC (build 173.3942.35) is available. This build features the ability to run and auto-correct all the RuboCop inspections in your project through the Run Inspection by Name action.

This feature is a great time-saver as with it you don’t have to manually look for every code smell in your project when, for example, you are about to commit some important changes. Simply go to Code | Run Inspection by Name, and type the name of the wanted inspection (obviously, “rubocop”, in our case):

As you see, in the opened window you can choose whether to inspect the whole project, a particular file, directories, file types, or even file masks.

Hit OK once you’ve defined your scope. Now you can review and fix every auto-correctable offense, or choose all items and fix the issues in bulk:

That’s it! If you have any comments, problems, or suggestions regarding this new ability, feel free to contribute to the related issue.

Other improvements

Download RubyMine 2017.3.1 RC

See the release notes for the full list of improvements, and please report any issues to the bug tracker.

Cheers,
Your RubyMine team

This entry was posted in Announcement, Feature, Uncategorized and tagged , , . Bookmark the permalink.

8 Responses to Find & Fix all RuboCop Inspections in one go

  1. Hi RubyMine team!

    Product keeps getting better – thank you!

    We have a custom, globally-installed shell script (committer --fix) we use to format our code that wraps the RuboCop autofix command + a couple other things.

    The script complements our existing Rubocop setup, which is already used in the inspection profile.

    We’d love for our committer --fix to be triggered instead of the builtin RubyMine reformat functionality. Is there any way to configure this?

    • Artem Sarkisov says:

      Hey! Thank you for your feedback. Did you try to add your custom to the External tools (Preferences / Settings | Tools | External tools)? Here’s the related doc https://www.jetbrains.com/help/ruby/settings-tools-external-tools.html

      Or probably you could also try to configure your formatter with the File Wathers plugin (plugin https://plugins.jetbrains.com/plugin/7177-file-watchers). Here’s also the related doc https://www.jetbrains.com/help/idea/using-file-watchers.html.

      Please let us know if any of these help.

      • Thanks for this suggestion Artem!

        I experimented with the External Tools settings. It seems powerful, but it doesn’t seem to execute the command in the context of the right terminal environment, so I can’t run bundle exec command – it’s saying that bundle is not installed.

        RubyMine’s Terminal tab seems to be working properly tho – I can bundle install and bundle exec rubocop just fine with it. Any ideas what might be wrong?

        Best
        Vaibhav

        • Olga Kuvardina says:

          Hello Vaibhav,
          would it be possible to run gem env from the Terminal where your command works and adding it to a script being run as External tool and provide both outputs?

          • Copy-paste below. Note that I’m a chruby usre. External tools uses my system ruby, why the terminal uses the real version (2.3.4) specified in .ruby-version.

            ========
            From External Tools:

            ./script.sh script.sh
            /Users/vaibhav.mallya/workspace/zenpayroll
            RubyGems Environment:
            – RUBYGEMS VERSION: 2.5.2.3
            – RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin17]
            – INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.3.0
            – USER INSTALLATION DIRECTORY: /Users/vaibhav.mallya/.gem/ruby/2.3.0
            – RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
            – EXECUTABLE DIRECTORY: /usr/local/bin
            – SPEC CACHE DIRECTORY: /Users/vaibhav.mallya/.gem/specs
            – SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
            – RUBYGEMS PLATFORMS:
            – ruby
            – universal-darwin-17
            – GEM PATHS:
            – /Library/Ruby/Gems/2.3.0
            – /Users/vaibhav.mallya/.gem/ruby/2.3.0
            – /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0
            – GEM CONFIGURATION:
            – :update_sources => true
            – :verbose => true
            – :backtrace => false
            – :bulk_threshold => 1000
            – REMOTE SOURCES:
            https://rubygems.org/
            – SHELL PATH:
            – /usr/local/bin
            – /usr/bin
            – /bin
            – /usr/sbin
            – /sbin
            – /opt/puppetlabs/bin
            – /usr/local/munki

            Process finished with exit code 0

            From the terminal:
            us-vmallya:zenpayroll vaibhav.mallya$ pwd
            /Users/vaibhav.mallya/workspace/zenpayroll
            us-vmallya:zenpayroll vaibhav.mallya$ gem env
            RubyGems Environment:
            – RUBYGEMS VERSION: 2.5.2
            – RUBY VERSION: 2.3.4 (2017-03-30 patchlevel 301) [x86_64-darwin17]
            – INSTALLATION DIRECTORY: /Users/vaibhav.mallya/.gem/ruby/2.3.4
            – USER INSTALLATION DIRECTORY: /Users/vaibhav.mallya/.gem/ruby/2.3.0
            – RUBY EXECUTABLE: /Users/vaibhav.mallya/.rubies/ruby-2.3.4/bin/ruby
            – EXECUTABLE DIRECTORY: /Users/vaibhav.mallya/.gem/ruby/2.3.4/bin
            – SPEC CACHE DIRECTORY: /Users/vaibhav.mallya/.gem/specs
            – SYSTEM CONFIGURATION DIRECTORY: /Users/vaibhav.mallya/.rubies/ruby-2.3.4/etc
            – RUBYGEMS PLATFORMS:
            – ruby
            – x86_64-darwin-17
            – GEM PATHS:
            – /Users/vaibhav.mallya/.gem/ruby/2.3.4
            – /Users/vaibhav.mallya/.rubies/ruby-2.3.4/lib/ruby/gems/2.3.0
            – GEM CONFIGURATION:
            – :update_sources => true
            – :verbose => true
            – :backtrace => false
            – :bulk_threshold => 1000
            – REMOTE SOURCES:
            https://rubygems.org/
            – SHELL PATH:
            – /Users/vaibhav.mallya/.gem/ruby/2.3.4/bin
            – /Users/vaibhav.mallya/.rubies/ruby-2.3.4/lib/ruby/gems/2.3.0/bin
            – /Users/vaibhav.mallya/.rubies/ruby-2.3.4/bin
            – /usr/local/bin
            – /usr/bin
            – /bin
            – /usr/sbin
            – /sbin
            – /opt/puppetlabs/bin
            – /usr/local/munki
            – /Users/vaibhav.mallya/workspace/zenpayroll/node_modules/.bin
            us-vmallya:zenpayroll vaibhav.mallya$

            • Olga Kuvardina says:

              Have you tried specifying another path to the Ruby executable of the version you’d like to use?

              • Vaibhav Mallya says:

                Hi Olga,
                Where exactly might I do that? I might be misunderstanding – I’ve already updated the preferences here:


                Languages and Frameworks -> Ruby SDK and Gems -> zenpayroll -> chruby: ruby-2.3.4

                Which is why the Terminal shows this:

Leave a Reply

Your email address will not be published. Required fields are marked *