Skip to content

Commit 17640ad

Browse files
authored
Merge pull request #2042 from koic/pluginfy_with_lint_roller
Pluginfy RuboCop RSpec
2 parents d29fd64 + 5f09fdf commit 17640ad

File tree

12 files changed

+61
-81
lines changed

12 files changed

+61
-81
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
- uses: actions/checkout@v4
9292
- name: Use oldest RuboCop allowed by gemspec
9393
run: |
94-
sed -nr "s/ *spec.add_dependency 'rubocop', '~> ([0-9\.]+)'/gem 'rubocop', '= \1'/p" \
94+
sed -nr "s/ *spec.add_dependency 'rubocop'.*'>= ([0-9\.]+)'/gem 'rubocop', '= \1'/p" \
9595
rubocop-rspec.gemspec > Gemfile.local
9696
cat Gemfile.local
9797
- uses: ruby/setup-ruby@v1

.rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
inherit_from: .rubocop_todo.yml
22

3-
require:
3+
plugins:
44
- rubocop-performance
55
- rubocop-rake
66
- rubocop-rspec
7-
- rubocop/cop/internal_affairs
7+
- rubocop-internal_affairs
88

99
AllCops:
1010
DisplayCopNames: true

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Don't let `RSpec/PredicateMatcher` replace `respond_to?` with two arguments with the RSpec `respond_to` matcher. ([@bquorning])
66
- Fix `RSpec/PredicateMatcher` support for `eql` and `equal` matchers. ([@bquorning])
7+
- Pluginfy RuboCop RSpec. ([@koic])
78

89
## 3.4.0 (2025-01-20)
910

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,34 @@ ways to do this:
4848
Put this into your `.rubocop.yml`.
4949

5050
```yaml
51-
require: rubocop-rspec
51+
plugins: rubocop-rspec
5252
```
5353
5454
Alternatively, use the following array notation when specifying multiple extensions.
5555
5656
```yaml
57-
require:
57+
plugins:
5858
- rubocop-other-extension
5959
- rubocop-rspec
6060
```
6161
6262
Now you can run `rubocop` and it will automatically load the RuboCop RSpec
6363
cops together with the standard cops.
6464

65+
> [!NOTE]
66+
> The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
67+
6568
### Command line
6669

6770
```bash
68-
rubocop --require rubocop-rspec
71+
rubocop --plugin rubocop-rspec
6972
```
7073

7174
### Rake task
7275

7376
```ruby
7477
RuboCop::RakeTask.new do |task|
75-
task.requires << 'rubocop-rspec'
78+
task.plugins << 'rubocop-rspec'
7679
end
7780
```
7881

docs/modules/ROOT/pages/usage.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@ There are three ways to do this:
88
Put this into your `.rubocop.yml`:
99

1010
----
11-
require: rubocop-rspec
11+
plugins: rubocop-rspec
1212
----
1313

1414
or, if you are using several extensions:
1515

1616
----
17-
require:
17+
plugins:
1818
- rubocop-rspec
1919
- rubocop-performance
2020
----
2121

2222
Now you can run `rubocop` and it will automatically load the RuboCop RSpec
2323
cops together with the standard cops.
2424

25+
NOTE: The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
26+
2527
=== RSpec DSL configuration
2628

2729
In case you https://github.com/rspec/rspec-core/blob/b0d0843a285693c64cdbe0c85726db155b46047e/lib/rspec/core/configuration.rb#L1122[define aliases for RSpec DSL], i.e. examples, example groups, hooks, or include example statements, you need to configure it so those elements are properly detected by RuboCop RSpec.
@@ -78,15 +80,15 @@ RuboCop RSpec's https://github.com/rubocop/rubocop-rspec/blob/a43424527c09fae2e6
7880

7981
[source,bash]
8082
----
81-
$ rubocop --require rubocop-rspec
83+
$ rubocop --plugin rubocop-rspec
8284
----
8385

8486
== Rake task
8587

8688
[source,ruby]
8789
----
8890
RuboCop::RakeTask.new do |task|
89-
task.requires << 'rubocop-rspec'
91+
task.plugins << 'rubocop-rspec'
9092
end
9193
----
9294

lib/rubocop-rspec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
require 'rubocop'
77

88
require_relative 'rubocop/rspec'
9-
require_relative 'rubocop/rspec/inject'
109
require_relative 'rubocop/rspec/language'
1110
require_relative 'rubocop/rspec/node'
11+
require_relative 'rubocop/rspec/plugin'
1212
require_relative 'rubocop/rspec/version'
1313
require_relative 'rubocop/rspec/wording'
1414

@@ -34,8 +34,6 @@
3434
require_relative 'rubocop/rspec/example_group'
3535
require_relative 'rubocop/rspec/hook'
3636

37-
RuboCop::RSpec::Inject.defaults!
38-
3937
require_relative 'rubocop/cop/rspec_cops'
4038

4139
# We have to register our autocorrect incompatibilities in RuboCop's cops

lib/rubocop/rspec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,5 @@
33
module RuboCop
44
# RuboCop RSpec project namespace
55
module RSpec
6-
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
7-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
8-
9-
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
10-
11-
::RuboCop::ConfigObsoletion.files << PROJECT_ROOT.join('config',
12-
'obsoletion.yml')
136
end
147
end

lib/rubocop/rspec/inject.rb

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

lib/rubocop/rspec/plugin.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
require 'lint_roller'
4+
5+
module RuboCop
6+
module RSpec
7+
# A plugin that integrates RuboCop RSpec with RuboCop's plugin system.
8+
class Plugin < LintRoller::Plugin
9+
# :nocov:
10+
def about
11+
LintRoller::About.new(
12+
name: 'rubocop-rspec',
13+
version: Version::STRING,
14+
homepage: 'https://github.com/rubocop/rubocop-rspec',
15+
description: 'Code style checking for RSpec files.'
16+
)
17+
end
18+
# :nocov:
19+
20+
def supported?(context)
21+
context.engine == :rubocop
22+
end
23+
24+
def rules(_context)
25+
project_root = Pathname.new(__dir__).join('../../..')
26+
27+
ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')
28+
29+
LintRoller::Rules.new(
30+
type: :path,
31+
config_format: :rubocop,
32+
value: project_root.join('config/default.yml')
33+
)
34+
end
35+
end
36+
end
37+
end

rubocop-rspec.gemspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ Gem::Specification.new do |spec|
3434
spec.metadata = {
3535
'changelog_uri' => 'https://github.com/rubocop/rubocop-rspec/blob/master/CHANGELOG.md',
3636
'documentation_uri' => 'https://docs.rubocop.org/rubocop-rspec/',
37-
'rubygems_mfa_required' => 'true'
37+
'rubygems_mfa_required' => 'true',
38+
'default_lint_roller_plugin' => 'RuboCop::RSpec::Plugin'
3839
}
3940

40-
spec.add_dependency 'rubocop', '~> 1.61'
41+
spec.add_dependency 'lint_roller', '~> 1.1'
42+
spec.add_dependency 'rubocop', '~> 1.72', '>= 1.72.1'
4143
end

0 commit comments

Comments
 (0)