Skip to content

Commit c0e77f4

Browse files
authored
Pluginfy RuboCop Airbnb (#212)
This PR adds support for RuboCop's Plugin feature. It replaces the ad-hoc `Inject` hack with the RuboCop plugin system introduced in RuboCop 1.72. - rubocop/rubocop#13792 - https://docs.rubocop.org/rubocop/plugin_migration_guide.html Accordingly, rubocop-airbnb has been updated to require specific versions of the following RuboCop extension plugins it depends on - rubocop-performance (`~> 1.24`) - rubocop-rails (`~> 2.30`) - rubocop-rspec (`~> 3.5`) The most significant change is that rubocop-rspec has been updated from version 2 to version 3. As a result, `RSpec/Capybara` and `RSpec/FactoryBot` have been extracted into the following extension gems: - rubocop-capybara - rubocop-factory_bot This PR adds dependencies on both rubocop-capybara and rubocop-rspec extensions to maintain the previous rubocop-rspec configuration. `RSpec/FilePath` has been split into `RSpec/SpecFilePathFormat` and `RSpec/SpecFilePathSuffix`, so the original disabling has been retained in the configuration. Similarly, `RSpec/Capybara/FeatureMethods` remains disabled as `RSpec/Dialect`. https://github.com/rubocop/rubocop-rspec/blob/v3.5.0/config/obsoletion.yml Resolves rubocop/rubocop-factory_bot#147.
1 parent c53a8a8 commit c0e77f4

File tree

12 files changed

+88
-61
lines changed

12 files changed

+88
-61
lines changed

rubocop-airbnb/.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
inherit_from:
22
- .rubocop_airbnb.yml
3-
- ./config/default.yml
3+
4+
plugins:
5+
- rubocop-airbnb
46

57
AllCops:
68
CacheRootDirectory: tmp/rubocop

rubocop-airbnb/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ways to do this:
2929
First Create a new file `.rubocop_airbnb.yml` in the same directory as your `.rubocop.yml`
3030
this file should contain
3131
```
32-
require:
32+
plugins:
3333
- rubocop-airbnb
3434
```
3535

@@ -50,10 +50,13 @@ you could potentially experience a bunch of warnings from `.rubocop_todo.yml` fo
5050
Now you can run `rubocop` and it will automatically load the RuboCop Airbnb
5151
cops together with the standard cops.
5252

53+
> [!NOTE]
54+
> The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
55+
5356
### Command line
5457

5558
```bash
56-
rubocop --require rubocop-airbnb
59+
rubocop --plugin rubocop-airbnb
5760
```
5861

5962
## The Cops
@@ -70,4 +73,3 @@ Airbnb/PhraseBundleKeys:
7073
Exclude:
7174
- spec/my_poorly_named_spec_file.rb
7275
```
73-

rubocop-airbnb/config/default.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ RSpec:
2929
Include:
3030
- _spec.rb
3131
- "(?:^|/)spec/"
32-
RSpec/FactoryBot:
32+
FactoryBot:
3333
Include:
3434
- spec/factories/**/*.rb
3535
- features/support/factories/**/*.rb
3636

3737
inherit_from:
3838
- './rubocop-airbnb.yml'
3939
- './rubocop-bundler.yml'
40+
- './rubocop-capybara.yml'
41+
- './rubocop-factory_bot.yml'
4042
- './rubocop-gemspec.yml'
4143
- './rubocop-layout.yml'
4244
- './rubocop-lint.yml'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
plugins:
2+
- rubocop-capybara
3+
4+
Capybara/CurrentPathExpectation:
5+
Description: Checks that no expectations are set on Capybara's `current_path`.
6+
Enabled: false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins:
2+
- rubocop-factory_bot
3+
4+
FactoryBot/AttributeDefinedStatically:
5+
Description: Always declare attribute values as blocks.
6+
Enabled: false
7+
8+
FactoryBot/CreateList:
9+
Description: Checks for create_list usage.
10+
Enabled: true

rubocop-airbnb/config/rubocop-performance.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require:
1+
plugins:
22
- rubocop-performance
33

44
Performance/Caller:
@@ -122,4 +122,3 @@ Performance/UnfreezeString:
122122

123123
Performance/UriDefaultParser:
124124
Enabled: false
125-

rubocop-airbnb/config/rubocop-rails.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require:
1+
plugins:
22
- rubocop-rails
33

44
# before_action doesn't seem to exist, so this doesn't make sense.

rubocop-airbnb/config/rubocop-rspec.yml

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require:
1+
plugins:
22
- rubocop-rspec
33

44
RSpec/AlignLeftLetBrace:
@@ -53,6 +53,10 @@ RSpec/DescribedClass:
5353
Description: 'Use `described_class` for tested class / module'
5454
Enabled: false
5555

56+
RSpec/Dialect:
57+
Description: Enforces custom RSpec dialects.
58+
Enabled: false
59+
5660
RSpec/EmptyExampleGroup:
5761
Description: Checks if an example group does not include any tests.
5862
Enabled: true
@@ -110,13 +114,6 @@ RSpec/ExpectOutput:
110114
Description: Checks for opportunities to use `expect { ... }.to output`.
111115
Enabled: false
112116

113-
RSpec/FilePath:
114-
Description: 'Checks the file and folder naming of the spec file.'
115-
Enabled: false
116-
CustomTransform:
117-
RuboCop: rubocop
118-
RSpec: rspec
119-
120117
RSpec/Focus:
121118
Description: Checks if examples are focused.
122119
Enabled: false
@@ -293,6 +290,17 @@ RSpec/SingleArgumentMessageChain:
293290
Description: Checks that chains of messages contain more than one element.
294291
Enabled: true
295292

293+
RSpec/SpecFilePathFormat:
294+
Description: Checks that spec file paths are consistent and well-formed.
295+
Enabled: false
296+
CustomTransform:
297+
RuboCop: rubocop
298+
RSpec: rspec
299+
300+
RSpec/SpecFilePathSuffix:
301+
Description: Checks that spec file paths suffix are consistent and well-formed.
302+
Enabled: false
303+
296304
RSpec/SubjectStub:
297305
Description: Checks for stubbed test subjects.
298306
Enabled: false
@@ -308,19 +316,3 @@ RSpec/VerifiedDoubles:
308316
RSpec/VoidExpect:
309317
Description: This cop checks void `expect()`.
310318
Enabled: false
311-
312-
RSpec/Capybara/CurrentPathExpectation:
313-
Description: Checks that no expectations are set on Capybara's `current_path`.
314-
Enabled: false
315-
316-
RSpec/Capybara/FeatureMethods:
317-
Description: Checks for consistent method usage in feature specs.
318-
Enabled: false
319-
320-
RSpec/FactoryBot/AttributeDefinedStatically:
321-
Description: Always declare attribute values as blocks.
322-
Enabled: false
323-
324-
RSpec/FactoryBot/CreateList:
325-
Description: Checks for create_list usage.
326-
Enabled: true

rubocop-airbnb/lib/rubocop-airbnb.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
require 'rubocop-performance'
88
require 'rubocop-rails'
99

10-
require 'rubocop/airbnb'
11-
require 'rubocop/airbnb/inject'
12-
require 'rubocop/airbnb/version'
13-
14-
RuboCop::Airbnb::Inject.defaults!
10+
require_relative 'rubocop/airbnb'
11+
require_relative 'rubocop/airbnb/plugin'
12+
require_relative 'rubocop/airbnb/version'

rubocop-airbnb/lib/rubocop/airbnb/inject.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)