Skip to content

Commit 897b22b

Browse files
authored
Merge pull request #1434 from koic/pluginfy_with_lint_roller
Pluginfy RuboCop Rails
2 parents 67066d7 + aeb3cac commit 897b22b

File tree

13 files changed

+56
-63
lines changed

13 files changed

+56
-63
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
-e "/gem 'rubocop-performance',/d" \
8484
-e "/gem 'rubocop-rspec',/d" -i Gemfile
8585
cat << EOF > Gemfile.local
86-
gem 'rubocop', '1.52.0' # Specify the oldest supported RuboCop version
86+
gem 'rubocop', '1.72.1'
8787
EOF
8888
- uses: ruby/setup-ruby@v1
8989
with:

.rubocop.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# This is the configuration used to check the rubocop source code.
22

33
inherit_from: .rubocop_todo.yml
4+
plugins:
5+
- rubocop-internal_affairs
6+
- rubocop-rails
7+
48
require:
5-
- rubocop/cop/internal_affairs
69
- rubocop-performance
7-
- rubocop-rails
810
- rubocop-rspec
911

1012
AllCops:

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,36 @@ ways to do this:
3131
Put this into your `.rubocop.yml`.
3232

3333
```yaml
34-
require: rubocop-rails
34+
plugins: rubocop-rails
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-rails
4343
```
4444
4545
Now you can run `rubocop` and it will automatically load the RuboCop Rails
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
```sh
51-
$ rubocop --require rubocop-rails
54+
$ rubocop --plugin rubocop-rails
5255
```
5356

54-
Note: `--rails` option is required while `rubocop` command supports `--rails` option.
55-
5657
### Rake task
5758

5859
```ruby
5960
require 'rubocop/rake_task'
6061
6162
RuboCop::RakeTask.new do |task|
62-
task.requires << 'rubocop-rails'
63+
task.plugins << 'rubocop-rails'
6364
end
6465
```
6566

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1434](https://github.com/rubocop/rubocop-rails/pull/1434): Pluginfy RuboCop Rails. ([@koic][])

docs/modules/ROOT/pages/usage.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Put this into your `.rubocop.yml`.
99

1010
[source,yaml]
1111
----
12-
require: rubocop-rails
12+
plugins: rubocop-rails
1313
----
1414

1515
Now you can run `rubocop` and it will automatically load the RuboCop Rails
@@ -19,18 +19,20 @@ cops together with the standard cops.
1919

2020
[source,sh]
2121
----
22-
$ rubocop --require rubocop-rails
22+
$ rubocop --plugin rubocop-rails
2323
----
2424

2525
== Rake task
2626

2727
[source,ruby]
2828
----
2929
RuboCop::RakeTask.new do |task|
30-
task.requires << 'rubocop-rails'
30+
task.plugins << 'rubocop-rails'
3131
end
3232
----
3333

34+
NOTE: The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
35+
3436
== RuboCop Rails configuration
3537

3638
The following settings specific to RuboCop Rails can be configured in `.rubocop.yml`.

lib/rubocop-rails.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77

88
require_relative 'rubocop/rails'
99
require_relative 'rubocop/rails/version'
10-
require_relative 'rubocop/rails/inject'
1110
require_relative 'rubocop/rails/schema_loader'
1211
require_relative 'rubocop/rails/schema_loader/schema'
13-
14-
RuboCop::Rails::Inject.defaults!
15-
12+
require_relative 'rubocop/rails/plugin'
1613
require_relative 'rubocop/cop/rails_cops'
1714

1815
require_relative 'rubocop/rails/migration_file_skippable'

lib/rubocop/rails.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# frozen_string_literal: true
22

33
module RuboCop
4-
# RuboCop Rails project namespace
4+
# RuboCop Rails project namespace.
55
module Rails
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', 'obsoletion.yml')
126
end
137
end

lib/rubocop/rails/inject.rb

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

lib/rubocop/rails/plugin.rb

Lines changed: 31 additions & 0 deletions
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 Rails
7+
# A plugin that integrates RuboCop Rails with RuboCop's plugin system.
8+
class Plugin < LintRoller::Plugin
9+
def about
10+
LintRoller::About.new(
11+
name: 'rubocop-rails',
12+
version: Version::STRING,
13+
homepage: 'https://github.com/rubocop/rubocop-rails',
14+
description: 'A RuboCop extension focused on enforcing Rails best practices and coding conventions.'
15+
)
16+
end
17+
18+
def supported?(context)
19+
context.engine == :rubocop
20+
end
21+
22+
def rules(_context)
23+
project_root = Pathname.new(__dir__).join('../../..')
24+
25+
ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')
26+
27+
LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join('config', 'default.yml'))
28+
end
29+
end
30+
end
31+
end

rubocop-rails.gemspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ Gem::Specification.new do |s|
2828
'source_code_uri' => 'https://github.com/rubocop/rubocop-rails/',
2929
'documentation_uri' => "https://docs.rubocop.org/rubocop-rails/#{RuboCop::Rails::Version.document_version}/",
3030
'bug_tracker_uri' => 'https://github.com/rubocop/rubocop-rails/issues',
31-
'rubygems_mfa_required' => 'true'
31+
'rubygems_mfa_required' => 'true',
32+
'default_lint_roller_plugin' => 'RuboCop::Rails::Plugin'
3233
}
3334

3435
s.add_dependency 'activesupport', '>= 4.2.0'
3536
# Rack::Utils::SYMBOL_TO_STATUS_CODE, which is used by HttpStatus cop, was
3637
# introduced in rack 1.1
38+
s.add_dependency 'lint_roller', '~> 1.1'
3739
s.add_dependency 'rack', '>= 1.1'
38-
s.add_dependency 'rubocop', '>= 1.52.0', '< 2.0'
40+
s.add_dependency 'rubocop', '>= 1.72.1', '< 2.0'
3941
s.add_dependency 'rubocop-ast', '>= 1.38.0', '< 2.0'
4042
end

0 commit comments

Comments
 (0)