Skip to content

Commit 9a21bfd

Browse files
authoredFeb 15, 2025
Merge pull request #58 from koic/plugin_lint_roller
Pluginfy RuboCop Rake
2 parents bd44ddb + 658715c commit 9a21bfd

10 files changed

+49
-40
lines changed
 

‎.rubocop.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
inherit_from: .rubocop_todo.yml
22

3-
require:
4-
- rubocop/cop/internal_affairs
3+
plugins:
4+
- rubocop-internal_affairs
55
- rubocop-rake
6+
7+
require:
68
- rubocop-rspec
79

810
AllCops:

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master (unreleased)
44

5+
* [#58](https://github.com/rubocop/rubocop-rake/pull/58): Pluginfy RuboCop Rake. ([@koic][])
56
* [#57](https://github.com/rubocop/rubocop-rake/pull/57): Drop support Ruby 2.5 and 2.6 for runtime environment. ([@koic][])
67

78
## 0.6.0 (2021-06-29)

‎Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ gemspec
77

88
gem "rake", "~> 13.0"
99
gem 'rspec'
10-
gem 'rubocop', '>= 0.76'
10+
gem 'rubocop', '>= 1.72.1'
1111
gem 'rubocop-rspec'

‎README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,27 @@ ways to do this:
3131
Put this into your `.rubocop.yml`.
3232

3333
```yaml
34-
require: rubocop-rake
34+
plugins: rubocop-rake
3535
```
3636
3737
Alternatively, use the following array notation when specifying multiple extensions.
3838
3939
```yaml
40-
require:
40+
plugins:
4141
- rubocop-other-extension
4242
- rubocop-rake
4343
```
4444
4545
Now you can run `rubocop` and it will automatically load the RuboCop Rake
4646
cops together with the standard cops.
4747

48+
> [!NOTE]
49+
> The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
50+
4851
### Command line
4952

5053
```bash
51-
rubocop --require rubocop-rake
54+
rubocop --plugin rubocop-rake
5255
```
5356

5457
### Rake task
@@ -57,7 +60,7 @@ rubocop --require rubocop-rake
5760
require 'rubocop/rake_task'
5861
5962
RuboCop::RakeTask.new do |task|
60-
task.requires << 'rubocop-rake'
63+
task.plugins << 'rubocop-rake'
6164
end
6265
```
6366

@@ -71,4 +74,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
7174
## Contributing
7275

7376
Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop/rubocop-rake.
74-

‎lib/rubocop-rake.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
require_relative 'rubocop/rake'
66
require_relative 'rubocop/rake/version'
7-
require_relative 'rubocop/rake/inject'
8-
9-
RuboCop::Rake::Inject.defaults!
7+
require_relative 'rubocop/rake/plugin'
108

119
require_relative 'rubocop/cop/rake/helper/class_definition'
1210
require_relative 'rubocop/cop/rake/helper/on_task'

‎lib/rubocop/rake.rb

-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,5 @@ module RuboCop
66
# :nodoc:
77
module Rake
88
class Error < StandardError; end
9-
10-
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
11-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
12-
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
13-
14-
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
159
end
1610
end

‎lib/rubocop/rake/inject.rb

-19
This file was deleted.

‎lib/rubocop/rake/plugin.rb

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

‎rubocop-rake.gemspec

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
1919
'homepage_uri' => spec.homepage,
2020
'source_code_uri' => spec.homepage,
2121
'changelog_uri' => "https://github.com/rubocop/rubocop-rake/blob/master/CHANGELOG.md",
22-
'rubygems_mfa_required' => 'true'
22+
'rubygems_mfa_required' => 'true',
23+
'default_lint_roller_plugin' => 'RuboCop::Rake::Plugin'
2324
}
2425

2526
# Specify which files should be added to the gem when it is released.
@@ -31,5 +32,6 @@ Gem::Specification.new do |spec|
3132
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
3233
spec.require_paths = ["lib"]
3334

34-
spec.add_dependency 'rubocop', '~> 1.0'
35+
spec.add_dependency 'lint_roller', '~> 1.1'
36+
spec.add_dependency 'rubocop', '>= 1.72.1'
3537
end

‎spec/spec_helper.rb

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
require 'rubocop/rspec/support'
55

66
RSpec.configure do |config|
7-
config.include RuboCop::RSpec::ExpectOffense
8-
97
config.disable_monkey_patching!
108
config.raise_errors_for_deprecations!
119
config.raise_on_warning = true

0 commit comments

Comments
 (0)