Skip to content

Commit 55f5aa0

Browse files
committed
Fix glob pattern for Includes and Exclude
We had **/, to support directories nested within engines or packwerk dirs This also matched against directory names outside the project Adding ../ scopes the glob to the project directory
1 parent 84c131f commit 55f5aa0

File tree

4 files changed

+149
-60
lines changed

4 files changed

+149
-60
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1536](https://github.com/rubocop/rubocop-rails/issues/1536): Fix glob pattern. We added '**/' to support packwerk and engines, but this will glob directories above the project directory. Change to optional '../**/' ([@malmckay][])

config/default.yml

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ inherit_mode:
66

77
AllCops:
88
Exclude:
9-
- '**/app/assets/**/*'
9+
- '{../**/,}app/assets/**/*'
1010
- bin/*
1111
# Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
1212
# See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
@@ -94,8 +94,8 @@ Lint/UselessAccessModifier:
9494
Lint/UselessMethodDefinition:
9595
# Avoids conflict with `Rails/LexicallyScopedActionFilter` cop.
9696
Exclude:
97-
- '**/app/controllers/**/*.rb'
98-
- '**/app/mailers/**/*.rb'
97+
- '{../**/,}app/controllers/**/*.rb'
98+
- '{../**/,}app/mailers/**/*.rb'
9999

100100
Rails:
101101
Enabled: true
@@ -127,8 +127,8 @@ Rails/ActionFilter:
127127
- action
128128
- filter
129129
Include:
130-
- '**/app/controllers/**/*.rb'
131-
- '**/app/mailers/**/*.rb'
130+
- '{../**/,}app/controllers/**/*.rb'
131+
- '{../**/,}app/mailers/**/*.rb'
132132

133133
Rails/ActionOrder:
134134
Description: 'Enforce consistent ordering of controller actions.'
@@ -143,7 +143,7 @@ Rails/ActionOrder:
143143
- update
144144
- destroy
145145
Include:
146-
- '**/app/controllers/**/*.rb'
146+
- '{../**/,}app/controllers/**/*.rb'
147147

148148
Rails/ActiveRecordAliases:
149149
Description: >-
@@ -160,7 +160,7 @@ Rails/ActiveRecordCallbacksOrder:
160160
Enabled: 'pending'
161161
VersionAdded: '2.7'
162162
Include:
163-
- '**/app/models/**/*.rb'
163+
- '{../**/,}app/models/**/*.rb'
164164

165165
Rails/ActiveRecordOverride:
166166
Description: >-
@@ -171,7 +171,7 @@ Rails/ActiveRecordOverride:
171171
VersionAdded: '0.67'
172172
VersionChanged: '2.18'
173173
Include:
174-
- '**/app/models/**/*.rb'
174+
- '{../**/,}app/models/**/*.rb'
175175

176176
Rails/ActiveSupportAliases:
177177
Description: >-
@@ -258,7 +258,7 @@ Rails/AttributeDefaultBlockValue:
258258
Enabled: pending
259259
VersionAdded: '2.9'
260260
Include:
261-
- '**/app/models/**/*'
261+
- '{../**/,}app/models/**/*'
262262

263263
Rails/BelongsTo:
264264
Description: >-
@@ -317,8 +317,8 @@ Rails/ContentTag:
317317
# https://puma.io/puma/Puma/DSL.html#tag-instance_method
318318
# No helpers are used in normal models and configs.
319319
Exclude:
320-
- '**/app/models/**/*.rb'
321-
- '**/config/**/*.rb'
320+
- '{../**/,}app/models/**/*.rb'
321+
- '{../**/,}config/**/*.rb'
322322

323323
Rails/CreateTableWithTimestamps:
324324
Description: >-
@@ -379,7 +379,7 @@ Rails/Delegate:
379379
# violation. When set to false, this case is legal.
380380
EnforceForPrefixed: true
381381
Exclude:
382-
- '**/app/controllers/**/*.rb'
382+
- '{../**/,}app/controllers/**/*.rb'
383383

384384
Rails/DelegateAllowBlank:
385385
Description: 'Do not use allow_blank as an option to delegate.'
@@ -450,23 +450,23 @@ Rails/EnumHash:
450450
Enabled: true
451451
VersionAdded: '2.3'
452452
Include:
453-
- '**/app/models/**/*.rb'
453+
- '{../**/,}app/models/**/*.rb'
454454

455455
Rails/EnumSyntax:
456456
Description: 'Use positional arguments over keyword arguments when defining enums.'
457457
Enabled: pending
458458
Severity: warning
459459
VersionAdded: '2.26'
460460
Include:
461-
- '**/app/models/**/*.rb'
462-
- '**/lib/**/*.rb'
461+
- '{../**/,}app/models/**/*.rb'
462+
- '{../**/,}lib/**/*.rb'
463463

464464
Rails/EnumUniqueness:
465465
Description: 'Avoid duplicate integers in hash-syntax `enum` declaration.'
466466
Enabled: true
467467
VersionAdded: '0.46'
468468
Include:
469-
- '**/app/models/**/*.rb'
469+
- '{../**/,}app/models/**/*.rb'
470470

471471
Rails/Env:
472472
Description: 'Use Feature Flags or config instead of `Rails.env`.'
@@ -490,11 +490,11 @@ Rails/EnvironmentVariableAccess:
490490
VersionAdded: '2.10'
491491
VersionChanged: '2.24'
492492
Include:
493-
- '**/app/**/*.rb'
494-
- '**/config/initializers/**/*.rb'
495-
- '**/lib/**/*.rb'
493+
- '{../**/,}app/**/*.rb'
494+
- '{../**/,}config/initializers/**/*.rb'
495+
- '{../**/,}lib/**/*.rb'
496496
Exclude:
497-
- '**/lib/**/*.rake'
497+
- '{../**/,}lib/**/*.rake'
498498
AllowReads: false
499499
AllowWrites: false
500500

@@ -506,11 +506,11 @@ Rails/Exit:
506506
Enabled: true
507507
VersionAdded: '0.41'
508508
Include:
509-
- '**/app/**/*.rb'
510-
- '**/config/**/*.rb'
511-
- '**/lib/**/*.rb'
509+
- '{../**/,}app/**/*.rb'
510+
- '{../**/,}config/**/*.rb'
511+
- '{../**/,}lib/**/*.rb'
512512
Exclude:
513-
- '**/lib/**/*.rake'
513+
- '{../**/,}lib/**/*.rake'
514514

515515
Rails/ExpandedDateRange:
516516
Description: 'Checks for expanded date range.'
@@ -579,22 +579,22 @@ Rails/HasAndBelongsToMany:
579579
Enabled: true
580580
VersionAdded: '0.12'
581581
Include:
582-
- '**/app/models/**/*.rb'
582+
- '{../**/,}app/models/**/*.rb'
583583

584584
Rails/HasManyOrHasOneDependent:
585585
Description: 'Define the dependent option to the has_many and has_one associations.'
586586
StyleGuide: 'https://rails.rubystyle.guide#has_many-has_one-dependent-option'
587587
Enabled: true
588588
VersionAdded: '0.50'
589589
Include:
590-
- '**/app/models/**/*.rb'
590+
- '{../**/,}app/models/**/*.rb'
591591

592592
Rails/HelperInstanceVariable:
593593
Description: 'Do not use instance variables in helpers.'
594594
Enabled: true
595595
VersionAdded: '2.0'
596596
Include:
597-
- '**/app/helpers/**/*.rb'
597+
- '{../**/,}app/helpers/**/*.rb'
598598

599599
Rails/HttpPositionalArguments:
600600
Description: 'Use keyword arguments instead of positional arguments in http method calls.'
@@ -620,7 +620,7 @@ Rails/HttpStatusNameConsistency:
620620
Severity: warning
621621
VersionAdded: '<<next>>'
622622
Include:
623-
- '**/app/controllers/**/*.rb'
623+
- '{../**/,}app/controllers/**/*.rb'
624624

625625
Rails/I18nLazyLookup:
626626
Description: 'Checks for places where I18n "lazy" lookup can be used.'
@@ -633,7 +633,7 @@ Rails/I18nLazyLookup:
633633
- lazy
634634
- explicit
635635
Include:
636-
- '**/app/controllers/**/*.rb'
636+
- '{../**/,}app/controllers/**/*.rb'
637637

638638
Rails/I18nLocaleAssignment:
639639
Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
@@ -662,8 +662,8 @@ Rails/IgnoredSkipActionFilterOption:
662662
Enabled: true
663663
VersionAdded: '0.63'
664664
Include:
665-
- '**/app/controllers/**/*.rb'
666-
- '**/app/mailers/**/*.rb'
665+
- '{../**/,}app/controllers/**/*.rb'
666+
- '{../**/,}app/mailers/**/*.rb'
667667

668668
Rails/IndexBy:
669669
Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
@@ -693,7 +693,7 @@ Rails/InverseOf:
693693
VersionAdded: '0.52'
694694
IgnoreScopes: false
695695
Include:
696-
- '**/app/models/**/*.rb'
696+
- '{../**/,}app/models/**/*.rb'
697697

698698
Rails/LexicallyScopedActionFilter:
699699
Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
@@ -702,8 +702,8 @@ Rails/LexicallyScopedActionFilter:
702702
Safe: false
703703
VersionAdded: '0.52'
704704
Include:
705-
- '**/app/controllers/**/*.rb'
706-
- '**/app/mailers/**/*.rb'
705+
- '{../**/,}app/controllers/**/*.rb'
706+
- '{../**/,}app/mailers/**/*.rb'
707707

708708
Rails/LinkToBlank:
709709
Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
@@ -721,7 +721,7 @@ Rails/MailerName:
721721
SafeAutoCorrect: false
722722
VersionAdded: '2.7'
723723
Include:
724-
- '**/app/mailers/**/*.rb'
724+
- '{../**/,}app/mailers/**/*.rb'
725725

726726
Rails/MatchRoute:
727727
Description: >-
@@ -731,8 +731,8 @@ Rails/MatchRoute:
731731
Enabled: 'pending'
732732
VersionAdded: '2.7'
733733
Include:
734-
- '**/config/routes.rb'
735-
- '**/config/routes/**/*.rb'
734+
- '{../**/,}config/routes.rb'
735+
- '{../**/,}config/routes/**/*.rb'
736736

737737
Rails/MigrationClassName:
738738
Description: 'The class name of the migration should match its file name.'
@@ -748,8 +748,8 @@ Rails/MultipleRoutePaths:
748748
Severity: warning
749749
VersionAdded: '2.29'
750750
Include:
751-
- '**/config/routes.rb'
752-
- '**/config/routes/**/*.rb'
751+
- '{../**/,}config/routes.rb'
752+
- '{../**/,}config/routes/**/*.rb'
753753

754754
Rails/NegateInclude:
755755
Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
@@ -792,10 +792,10 @@ Rails/Output:
792792
VersionAdded: '0.15'
793793
VersionChanged: '0.19'
794794
Include:
795-
- '**/app/**/*.rb'
796-
- '**/config/**/*.rb'
795+
- '{../**/,}app/**/*.rb'
796+
- '{../**/,}config/**/*.rb'
797797
- db/**/*.rb
798-
- '**/lib/**/*.rb'
798+
- '{../**/,}lib/**/*.rb'
799799

800800
Rails/OutputSafety:
801801
Description: 'The use of `html_safe` or `raw` may be a security risk.'
@@ -868,7 +868,7 @@ Rails/RakeEnvironment:
868868
- '**/Rakefile'
869869
- '**/*.rake'
870870
Exclude:
871-
- '**/lib/capistrano/tasks/**/*.rake'
871+
- '{../**/,}lib/capistrano/tasks/**/*.rake'
872872

873873
Rails/ReadWriteAttribute:
874874
Description: >-
@@ -879,7 +879,7 @@ Rails/ReadWriteAttribute:
879879
VersionAdded: '0.20'
880880
VersionChanged: '0.29'
881881
Include:
882-
- '**/app/models/**/*.rb'
882+
- '{../**/,}app/models/**/*.rb'
883883

884884
Rails/RedirectBackOrTo:
885885
Description: >-
@@ -906,7 +906,7 @@ Rails/RedundantAllowNil:
906906
Enabled: true
907907
VersionAdded: '0.67'
908908
Include:
909-
- '**/app/models/**/*.rb'
909+
- '{../**/,}app/models/**/*.rb'
910910

911911
Rails/RedundantForeignKey:
912912
Description: 'Checks for associations where the `:foreign_key` option is redundant.'
@@ -1077,7 +1077,7 @@ Rails/ScopeArgs:
10771077
VersionAdded: '0.19'
10781078
VersionChanged: '2.12'
10791079
Include:
1080-
- '**/app/models/**/*.rb'
1080+
- '{../**/,}app/models/**/*.rb'
10811081

10821082
Rails/SelectMap:
10831083
Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
@@ -1146,7 +1146,7 @@ Rails/StrongParametersExpect:
11461146
Reference: 'https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect'
11471147
Enabled: pending
11481148
Include:
1149-
- '**/app/controllers/**/*.rb'
1149+
- '{../**/,}app/controllers/**/*.rb'
11501150
SafeAutoCorrect: false
11511151
VersionAdded: '2.29'
11521152

@@ -1157,7 +1157,7 @@ Rails/TableNameAssignment:
11571157
Enabled: false
11581158
VersionAdded: '2.14'
11591159
Include:
1160-
- '**/app/models/**/*.rb'
1160+
- '{../**/,}app/models/**/*.rb'
11611161

11621162
Rails/ThreeStateBooleanColumn:
11631163
Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
@@ -1241,7 +1241,7 @@ Rails/UniqueValidationWithoutIndex:
12411241
Enabled: true
12421242
VersionAdded: '2.5'
12431243
Include:
1244-
- '**/app/models/**/*.rb'
1244+
- '{../**/,}app/models/**/*.rb'
12451245

12461246
Rails/UnknownEnv:
12471247
Description: 'Use correct environment name.'
@@ -1260,7 +1260,7 @@ Rails/UnusedIgnoredColumns:
12601260
VersionAdded: '2.11'
12611261
VersionChanged: '2.25'
12621262
Include:
1263-
- '**/app/models/**/*.rb'
1263+
- '{../**/,}app/models/**/*.rb'
12641264

12651265
Rails/UnusedRenderContent:
12661266
Description: 'Do not specify body content for a response with a non-content status code.'
@@ -1274,7 +1274,7 @@ Rails/Validation:
12741274
VersionAdded: '0.9'
12751275
VersionChanged: '0.41'
12761276
Include:
1277-
- '**/app/models/**/*.rb'
1277+
- '{../**/,}app/models/**/*.rb'
12781278

12791279
Rails/WhereEquals:
12801280
Description: 'Pass conditions to `where` and `where.not` as a hash instead of manually constructing SQL.'

spec/project_spec.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,10 @@
158158
next if config[name][clusivity_key].nil?
159159

160160
config[name][clusivity_key].each do |clusivity_pattern|
161-
expect(clusivity_pattern).to match(%r{\*\*/app/}), <<~ERROR if clusivity_pattern.match?(%r{\bapp/})
162-
Invalid pattern for #{name} #{clusivity_key}: #{clusivity_pattern}
163-
ERROR
164-
expect(clusivity_pattern).to match(%r{\*\*/config/}), <<~ERROR if clusivity_pattern.match?(%r{\bconfig/})
165-
Invalid pattern for #{name} #{clusivity_key}: #{clusivity_pattern}
166-
ERROR
167-
expect(clusivity_pattern).to match(%r{\*\*/lib/}), <<~ERROR if clusivity_pattern.match?(%r{\blib/})
168-
Invalid pattern for #{name} #{clusivity_key}: #{clusivity_pattern}
169-
ERROR
161+
msg = "Invalid pattern for #{name} #{clusivity_key}: #{clusivity_pattern}"
162+
expect(clusivity_pattern).to match(%r[{../\*\*/,}app/]), msg if clusivity_pattern.match?(%r{\bapp/})
163+
expect(clusivity_pattern).to match(%r[{../\*\*/,}config/]), msg if clusivity_pattern.match?(%r{\bconfig/})
164+
expect(clusivity_pattern).to match(%r[{../\*\*/,}lib/]), msg if clusivity_pattern.match?(%r{\blib/})
170165
end
171166
end
172167
end

0 commit comments

Comments
 (0)