Skip to content

Commit

Permalink
Pluginfy rubocop-sequel (#50)
Browse files Browse the repository at this point in the history
This PR makes rubocop-sequel 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
  • Loading branch information
koic authored Feb 17, 2025
1 parent 2944206 commit 8e68f23
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
- 3.0
- 3.1
- 3.2
- 3.3
- 3.4
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
NewCops: enable

# Offense count: 1
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,25 @@ gem 'rubocop-sequel'
Add to your `.rubocop.yml`.

```
require: rubocop-sequel
plugins: rubocop-sequel
```

`rubocop` will now automatically load RuboCop Sequel
cops alongside with the standard cops.

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

```bash
rubocop --require rubocop-sequel
rubocop --plugin rubocop-sequel
```

### Rake task

```ruby
RuboCop::RakeTask.new do |task|
task.requires << 'rubocop-sequel'
task.plugins << 'rubocop-sequel'
end
```
4 changes: 1 addition & 3 deletions lib/rubocop-sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
require 'rubocop'
require 'rubocop/sequel'
require 'rubocop/sequel/version'
require 'rubocop/sequel/inject'

RuboCop::Sequel::Inject.defaults!
require 'rubocop/sequel/plugin'

require_relative 'rubocop/cop/sequel/helpers/migration'

Expand Down
18 changes: 0 additions & 18 deletions lib/rubocop/sequel/inject.rb

This file was deleted.

31 changes: 31 additions & 0 deletions lib/rubocop/sequel/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'lint_roller'

module RuboCop
module Sequel
# A plugin that integrates rubocop-sequel with RuboCop's plugin system.
class Plugin < LintRoller::Plugin
def about
LintRoller::About.new(
name: 'rubocop-sequel',
version: Version::STRING,
homepage: 'https://github.com/rubocop/rubocop-sequel',
description: 'Code style checking for Sequel.'
)
end

def supported?(context)
context.engine == :rubocop
end

def rules(_context)
LintRoller::Rules.new(
type: :path,
config_format: :rubocop,
value: Pathname.new(__dir__).join('../../../config/default.yml')
)
end
end
end
end
6 changes: 4 additions & 2 deletions rubocop-sequel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']
gem.version = '0.3.8'
gem.metadata['rubygems_mfa_required'] = 'true'
gem.metadata['default_lint_roller_plugin'] = 'RuboCop::Sequel::Plugin'

gem.required_ruby_version = '>= 2.5'
gem.required_ruby_version = '>= 2.7'

gem.add_dependency 'rubocop', '~> 1.0'
gem.add_dependency 'lint_roller', '~> 1.1'
gem.add_dependency 'rubocop', '~> 1.72.1'
end

0 comments on commit 8e68f23

Please sign in to comment.