Skip to content

Commit 911bdce

Browse files
committed
Pluginfy rubocop-i18n
This PR makes rubocop-i18n support RuboCop's Plugin feature. It replaces the ad-hoc `Inject` with RuboCop plugins introduced in RuboCop 1.72. Additionally, since RuboCop already requires Ruby 2.7 or higher as its runtime, the `required_ruby_version` will be updated to 2.7. Follow-up rubocop/rubocop#13792
1 parent e75d6b8 commit 911bdce

File tree

9 files changed

+50
-35
lines changed

9 files changed

+50
-35
lines changed

.rubocop.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
inherit_from: .rubocop_todo.yml
2+
3+
plugins:
4+
- rubocop-internal_affairs
5+
26
require:
3-
- rubocop/cop/internal_affairs
47
- rubocop-rake
58
- rubocop-rspec
69
- rubocop-performance
710

811
AllCops:
9-
TargetRubyVersion: 2.5
12+
TargetRubyVersion: 2.7
1013
NewCops: enable
1114

1215
# rubocop-i18n does not have config/default.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### [master (Unreleased)](https://github.com/rubocop/rubocop-i18n/compare/v3.1.0...master)
44

5+
* Pluginfy rubocop-i18n (#65)
6+
57
### [3.1.0](https://github.com/rubocop/rubocop-i18n/compare/v3.0.0...v3.1.0)
68

79
* Transfer ownership of rubocop-i18n from puppetlabs org to rubocop org (#62)

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ Or install it yourself as:
2828
## Usage
2929

3030
In your `rubocop.yml`:
31-
```
32-
require:
31+
32+
```yaml
33+
plugins:
3334
- rubocop-i18n
3435
...
3536
# You *must* choose GetText or Rails-i18n style checking
@@ -58,6 +59,9 @@ I18n/RailsI18n/DecorateString:
5859
Enabled: false
5960
```
6061
62+
> [!NOTE]
63+
> The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
64+
6165
## Cops
6266

6367
### I18n/GetText/DecorateString

lib/rubocop-i18n.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
require 'rubocop'
44

55
require_relative 'rubocop/i18n'
6-
require_relative 'rubocop/i18n/inject'
7-
8-
RuboCop::I18n::Inject.defaults!
9-
6+
require_relative 'rubocop/i18n/plugin'
107
require_relative 'rubocop/cop/i18n_cops'

lib/rubocop/i18n.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,5 @@
33
module RuboCop
44
# RuboCop I18n project namespace
55
module I18n
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)
106
end
117
end

lib/rubocop/i18n/inject.rb

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

lib/rubocop/i18n/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 I18n
7+
# A plugin that integrates rubocop-i18n with RuboCop's plugin system.
8+
class Plugin < LintRoller::Plugin
9+
def about
10+
LintRoller::About.new(
11+
name: 'rubocop-i18n',
12+
version: Version::STRING,
13+
homepage: 'https://github.com/rubocop/rubocop-i18n',
14+
description: 'RuboCop rules for i18n.'
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-i18n.gemspec

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ Gem::Specification.new do |spec|
2020
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2121
spec.require_paths = ['lib']
2222

23-
spec.required_ruby_version = '>= 2.5.8'
23+
spec.required_ruby_version = '>= 2.7.0'
2424

2525
spec.metadata = {
26-
'rubygems_mfa_required' => 'true'
26+
'rubygems_mfa_required' => 'true',
27+
'default_lint_roller_plugin' => 'RuboCop::I18n::Plugin'
2728
}
2829

29-
spec.add_dependency 'rubocop', '~> 1.0'
30+
spec.add_dependency 'lint_roller', '~> 1.1'
31+
spec.add_dependency 'rubocop', '~> 1.72.1'
3032
end

spec/spec_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,4 @@
3636
mocks.syntax = :expect # Disable `should_receive` and `stub`
3737
mocks.verify_partial_doubles = true
3838
end
39-
40-
config.include(RuboCop::RSpec::ExpectOffense)
4139
end

0 commit comments

Comments
 (0)