Skip to content

Commit ec7d02e

Browse files
authored
Merge pull request #79 from toptal/pluginfly
RuboCop plugin system via LintRoller
2 parents 25f544d + 7ce747e commit ec7d02e

File tree

10 files changed

+59
-13
lines changed

10 files changed

+59
-13
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ AllCops:
1818

1919
Naming/FileName:
2020
Exclude:
21+
- 'lib/rubocop-database_validations.rb'
2122
- 'example/Gemfile'
2223
- 'example/Rakefile'
2324

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## [2.0.0] - 20-03-2026
3+
## Unreleased - xxxx-xx-xx
4+
5+
- Add RuboCop plugin system via LintRoller for RuboCop >= 1.72
6+
7+
## [2.0.0] - 2026-03-20
48
### Improvements
59

610
- Add Rails 8.1 support

Gemfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,4 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
55
# Specify your gem's dependencies in database_validations.gemspec
66
gemspec
77

8-
group :test do
9-
gem 'rspec_junit_formatter', '~> 0.4.1'
10-
end
11-
128
eval(File.read(ENV['GEMFILE_PATH'])) if ENV['GEMFILE_PATH'] # rubocop:disable Security/Eval

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,20 @@ end
247247
## Using with RuboCop
248248

249249
DatabaseValidations provides custom cops for RuboCop to help you consistently apply the improvements.
250-
To use all of them, use `rubocop --require database_validations/rubocop/cops` or add to your `.rubocop.yml` file:
250+
251+
For RuboCop >= 1.72, add the plugin to your `.rubocop.yml` file:
251252

252253
```yaml
253-
require:
254-
- database_validations/rubocop/cops
254+
plugins:
255+
- database_validations:
256+
require_path: rubocop-database_validations
255257
```
256258
257-
Or you case use some specific cop directly:
259+
For older versions of RuboCop, use `require` instead:
260+
258261
```yaml
259262
require:
260-
- database_validations/rubocop/cop/belongs_to
261-
- database_validations/rubocop/cop/uniqueness_of
263+
- database_validations/rubocop/cops
262264
```
263265

264266
## Development

config/rubocop-default.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
DatabaseValidations/BelongsTo:
2+
Enabled: true
3+
4+
DatabaseValidations/UniquenessOf:
5+
Enabled: true

database_validations.gemspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ The main goal of the gem is to provide compatibility between database constraint
1717
and ActiveRecord validations with better performance and consistency."
1818
spec.homepage = 'https://github.com/toptal/database_validations'
1919
spec.license = 'MIT'
20-
spec.files = Dir['lib/**/*']
20+
spec.files = Dir['lib/**/*', 'config/**/*']
2121
spec.require_paths = ['lib']
2222
spec.required_ruby_version = '>= 3.2.0'
2323

24+
spec.metadata['default_lint_roller_plugin'] = 'RuboCop::DatabaseValidations::Plugin'
25+
2426
spec.add_dependency 'activerecord', '>= 7.2.0'
27+
spec.add_dependency 'lint_roller'
2528

2629
spec.add_development_dependency 'benchmark-ips'
2730
spec.add_development_dependency 'bundler'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'rubocop'
2+
3+
require_relative 'rubocop/database_validations'
4+
require_relative 'rubocop/database_validations/plugin'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require_relative '../../lib/database_validations/rubocop/cop/belongs_to'
2+
require_relative '../../lib/database_validations/rubocop/cop/uniqueness_of'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'lint_roller'
2+
require 'database_validations/version'
3+
4+
module RuboCop
5+
module DatabaseValidations
6+
class Plugin < LintRoller::Plugin
7+
def about
8+
LintRoller::About.new(
9+
name: 'rubocop-database_validations',
10+
version: ::DatabaseValidations::VERSION,
11+
homepage: 'https://github.com/toptal/database_validations',
12+
description: 'RuboCop cops for database_validations gem.'
13+
)
14+
end
15+
16+
def supported?(context)
17+
context.engine == :rubocop
18+
end
19+
20+
def rules(_context)
21+
LintRoller::Rules.new(
22+
type: :path,
23+
config_format: :rubocop,
24+
value: File.join(__dir__, '..', '..', '..', 'config', 'rubocop-default.yml')
25+
)
26+
end
27+
end
28+
end
29+
end

spec/rubocop/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'rubocop'
1+
require 'rubocop-database_validations'
22
require 'rubocop/rspec/support'
33
require 'database_validations/rubocop/cops'
44

0 commit comments

Comments
 (0)