Skip to content

Enable non-default locations of checked files #234

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

Open
ustimchik opened this issue Apr 13, 2020 · 4 comments · May be fixed by #1476
Open

Enable non-default locations of checked files #234

ustimchik opened this issue Apr 13, 2020 · 4 comments · May be fixed by #1476
Labels
feature request Request for new functionality

Comments

@ustimchik
Copy link

ustimchik commented Apr 13, 2020

When using engines, the path for controllers, models, etc. are different from the core application which forces gem users to enable "Include" for all cops with this configurable option.

It would be great if there was a possibility to have some configurable global parameters, for instance:

Rails:
  -controllers_path: '**/app/controllers'
  -models_path: '**/app/{models,decorators}'
@koic koic added the feature request Request for new functionality label Apr 14, 2020
@ianyamey
Copy link

@ustimchik: consider adding this to your .rubocop.yml:

inherit_mode:
    merge:
        - Exclude
        - Include

AllCops:
    Include:
        - lib/path/to/your/engines/**/*.rb

See: https://rubocop.readthedocs.io/en/latest/configuration/#unusual-files-that-would-not-be-included-by-default

@iuriialekseev
Copy link

iuriialekseev commented Jun 26, 2020

@ianyamey, it seems that this config somehow conflicts with rubocop-rails default config:

Finds 36 Rails/HasAndBelongsToMany offences

require:
  - ./linters/custom_cops.rb
  - rubocop-rails

inherit_mode:
  merge:
    - Exclude
    - Include

Still finds 36 Rails/HasAndBelongsToMany offences

require:
  - ./linters/custom_cops.rb
  - rubocop-rails

inherit_mode:
  merge:
    - Exclude
    - Include

AllCops:
  Include:
    - 'plugins/**/*.rb'

Only with specific rule overwrite it finds 50 Rails/HasAndBelongsToMany offenses and actually applies this rule to plugins/**/*.rb files

require:
  - ./linters/custom_cops.rb
  - rubocop-rails

inherit_mode:
  merge:
    - Exclude
    - Include

Rails/HasAndBelongsToMany:
  Include:
    - 'plugins/**/*.rb'

@jmuhlfel
Copy link

jmuhlfel commented Apr 8, 2022

I'm having this issue as well. It may be more straightforward to include engine paths (ex. engines/**/app/models/**/*) for the relevant cops in default.yml, instead of adding new config features.

@hlbowen
Copy link

hlbowen commented Jul 5, 2023

I am also having this issue, not with Engines but with Packwerk, which uses a similar subfolder structure - in my case it looks like packs/**/app/models/**/*. I'd like to apply the same rubocop config to all of my packs, but when I put this config in a root level .rubocop.yml, rubocop-rails doesn't apply the model/controller/etc-specific cops to any files within packs.

The only solution I've found so far is to copy my root-level .rubocop.yml into every single pack directory (packs/**/.rubocop.yml). This isn't sustainable and I would love to find a better option.

@tdeo tdeo linked a pull request May 5, 2025 that will close this issue
9 tasks
tdeo added a commit to tdeo/rubocop-rails that referenced this issue May 5, 2025
tdeo added a commit to tdeo/rubocop-rails that referenced this issue May 6, 2025
tdeo added a commit to tdeo/rubocop-rails that referenced this issue May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants