Skip to content

Rails/Output and Rails/Exit behavior differs depending on directory structure #1487

@mizoR

Description

@mizoR

We’ve encountered a situation where Rails/Output and Rails/Exit behave differently depending on the environment in which RuboCop is run.
Specifically, some files are linted in certain environments but not in others, even though the project content is the same.

Expected behavior

I think that Include and Exclude path patterns for cops like Rails/Output and Rails/Exit should be evaluated relative to the directory where the .rubocop.yml file resides. This would ensure consistent linting results regardless of the absolute location of the project on the filesystem or the environment where RuboCop is run.

Actual behavior

When running RuboCop in different environments where the project is mounted or checked out in different absolute paths (e.g., /app inside Docker vs. ~/Projects/myapp on macOS), the Include patterns such as **/app/**/*.rb seem to match different files. As a result, cops like Rails/Output or Rails/Exit detect offenses in some environments but not others, causing inconsistent linting results.

ref:

Steps to reproduce the problem

  1. Place a file with puts or exit in bin/ or another directory inside your project.
  2. Run RuboCop on two environments with different project root paths, e.g.:
    • ~/Projects/app
    • ~/Projects/myapp
  3. Observe that the file in bin/ is flagged in app but not myapp

Small example is: https://github.com/mizoR/rubocop-rails-1487

RuboCop version

$ bundle exec rubocop -V                                                                                                                                                                                                                                                                                                                                                                          rbenv:3.4.4 
1.75.8 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.44.1, analyzing as Ruby 3.4, running on ruby 3.4.4) [arm64-darwin24]
  - rubocop-rails 2.32.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions