Integrating RuboCop in RubyMine for Rails Project Consistency
Learn how to configure RubyMine to use the project's RuboCop SDK, ensuring IDE inspections match CI linting and implementing safe auto-corrections in Rails.
02 Sept 2025, 08:01 UTC

The Problem: Divergence Between IDE and CI Linting
Developers often face a "works on my machine" scenario where RubyMine shows no linting errors, but the Continuous Integration (CI) pipeline fails due to RuboCop offenses. This usually happens when the IDE uses a bundled RuboCop version or a global gem that differs from the project's Gemfile.lock. To achieve parity, RubyMine must be configured to use the exact RuboCop executable provided by the project's SDK.
Prerequisites
- RubyMine 2023.3 or newer installed.
- A Rails project with
rubocop(and optional plugins likerubocop-railsorrubocop-performance) listed in theGemfile. - A
.rubocop.ymlconfiguration file in the project root. - Bundler installed and
bundle installcompleted.
Configuring the RuboCop Executable
To ensure the IDE uses the project-specific version of RuboCop, you must link the inspection engine to the project SDK.
- Navigate to Settings (
Ctrl+Alt+S/Cmd+,) > Editor > Inspections. - Expand the Ruby section and locate RuboCop.
- Check the Enable box.
- In the configuration panel, select Use RuboCop from project SDK. This tells RubyMine to look for the gem within the current Ruby environment defined in your project settings rather than using a built-in version.
- Ensure Autodetect RuboCop configuration is checked. This allows RubyMine to automatically locate and respect your
.rubocop.ymlfile.
Optimizing Inspection Scope
Running static analysis on every file in a large Rails project can degrade IDE performance. You should limit the scope to avoid scanning generated or temporary files.
In the Inspections window, use the Scope dropdown to select Project Files. If you have large directories that are not part of your source code (e.g., vendor/, tmp/, or public/assets/), right-click those folders in the Project view and select Mark Directory as > Excluded. RubyMine will stop running RuboCop inspections on these paths.
Executing Inspections and Auto-Corrections
RubyMine provides three ways to interact with RuboCop offenses, depending on whether you need a quick fix or a project-wide audit.
Real-time Inline Fixes
When a line is underlined in the editor, place your cursor on the offense and press Alt+Enter. If the offense is marked as "safe" by RuboCop, you will see the option RuboCop: Fix offense. Selecting this applies the correction immediately to that specific line.
File-level Auto-correction
To fix all safe offenses in a single file, right-click the file in the Project tool window and select Run RuboCop with auto-correct. Note that this will only apply corrections that do not risk changing the behavior of your code.
Project-wide Analysis
To find all offenses across the application: go to Code > Inspect Code…. Select the scope (e.g., Whole Project) and click Analyze. The results will appear in the Problems tool window, grouped by offense type.
Comparing IDE Results with CI
To verify that your IDE is perfectly aligned with your CI pipeline, perform a manual cross-check using the terminal.
Run the following command in the RubyMine terminal (ensure you are in the project root):
bundle exec rubocop --format simple
Verification Check: Compare the list of offenses in the terminal output with the list in the Problems tool window after running Inspect Code. If the terminal reports offenses that the IDE does not show, verify that your .rubocop.yml is not being ignored and that you are using the "Project SDK" setting.
Handling Unsafe Corrections
RuboCop distinguishes between "safe" and "unsafe" corrections. RubyMine's built-in auto-correct features only execute safe corrections to prevent accidental logic changes. For unsafe corrections, you must use the terminal with explicit permissions:
# Run this in the project terminal with caution
bundle exec rubocop -A
Risk: The -A flag can change the semantics of your code. Always run this on a clean git branch and review the diff before committing.
Rollback and Recovery
Because RuboCop auto-correction modifies source files, the only reliable rollback mechanism is version control. If an auto-correct operation introduces bugs:
- Open the Commit tool window (
Ctrl+K/Cmd+K). - Review the changes in the affected files.
- Right-click the modified files and select Rollback to revert to the last committed state.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.