diff --git a/.rubocop.yml b/.rubocop.yml index 91e9cb0..b597e66 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -18,6 +18,7 @@ AllCops: Naming/FileName: Exclude: + - 'lib/rubocop-database_validations.rb' - 'example/Gemfile' - 'example/Rakefile' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4125eae..ccd2cb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog -## [2.0.0] - 20-03-2026 +## Unreleased - xxxx-xx-xx + +- Add RuboCop plugin system via LintRoller for RuboCop >= 1.72 + +## [2.0.0] - 2026-03-20 ### Improvements - Add Rails 8.1 support diff --git a/Gemfile b/Gemfile index 05e7795..f4d2411 100644 --- a/Gemfile +++ b/Gemfile @@ -5,8 +5,4 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in database_validations.gemspec gemspec -group :test do - gem 'rspec_junit_formatter', '~> 0.4.1' -end - eval(File.read(ENV['GEMFILE_PATH'])) if ENV['GEMFILE_PATH'] # rubocop:disable Security/Eval diff --git a/README.md b/README.md index cb07fea..21f7659 100644 --- a/README.md +++ b/README.md @@ -247,18 +247,20 @@ end ## Using with RuboCop DatabaseValidations provides custom cops for RuboCop to help you consistently apply the improvements. -To use all of them, use `rubocop --require database_validations/rubocop/cops` or add to your `.rubocop.yml` file: + +For RuboCop >= 1.72, add the plugin to your `.rubocop.yml` file: ```yaml -require: - - database_validations/rubocop/cops +plugins: + - database_validations: + require_path: rubocop-database_validations ``` -Or you case use some specific cop directly: +For older versions of RuboCop, use `require` instead: + ```yaml require: - - database_validations/rubocop/cop/belongs_to - - database_validations/rubocop/cop/uniqueness_of + - database_validations/rubocop/cops ``` ## Development diff --git a/config/rubocop-default.yml b/config/rubocop-default.yml new file mode 100644 index 0000000..868f7f2 --- /dev/null +++ b/config/rubocop-default.yml @@ -0,0 +1,5 @@ +DatabaseValidations/BelongsTo: + Enabled: true + +DatabaseValidations/UniquenessOf: + Enabled: true diff --git a/database_validations.gemspec b/database_validations.gemspec index 1490515..1f8b6ba 100644 --- a/database_validations.gemspec +++ b/database_validations.gemspec @@ -17,11 +17,14 @@ The main goal of the gem is to provide compatibility between database constraint and ActiveRecord validations with better performance and consistency." spec.homepage = 'https://github.com/toptal/database_validations' spec.license = 'MIT' - spec.files = Dir['lib/**/*'] + spec.files = Dir['lib/**/*', 'config/**/*'] spec.require_paths = ['lib'] spec.required_ruby_version = '>= 3.2.0' + spec.metadata['default_lint_roller_plugin'] = 'RuboCop::DatabaseValidations::Plugin' + spec.add_dependency 'activerecord', '>= 7.2.0' + spec.add_dependency 'lint_roller' spec.add_development_dependency 'benchmark-ips' spec.add_development_dependency 'bundler' diff --git a/lib/rubocop-database_validations.rb b/lib/rubocop-database_validations.rb new file mode 100644 index 0000000..518b47e --- /dev/null +++ b/lib/rubocop-database_validations.rb @@ -0,0 +1,4 @@ +require 'rubocop' + +require_relative 'rubocop/database_validations' +require_relative 'rubocop/database_validations/plugin' diff --git a/lib/rubocop/database_validations.rb b/lib/rubocop/database_validations.rb new file mode 100644 index 0000000..e48086e --- /dev/null +++ b/lib/rubocop/database_validations.rb @@ -0,0 +1,2 @@ +require_relative '../../lib/database_validations/rubocop/cop/belongs_to' +require_relative '../../lib/database_validations/rubocop/cop/uniqueness_of' diff --git a/lib/rubocop/database_validations/plugin.rb b/lib/rubocop/database_validations/plugin.rb new file mode 100644 index 0000000..b78a137 --- /dev/null +++ b/lib/rubocop/database_validations/plugin.rb @@ -0,0 +1,29 @@ +require 'lint_roller' +require 'database_validations/version' + +module RuboCop + module DatabaseValidations + class Plugin < LintRoller::Plugin + def about + LintRoller::About.new( + name: 'rubocop-database_validations', + version: ::DatabaseValidations::VERSION, + homepage: 'https://github.com/toptal/database_validations', + description: 'RuboCop cops for database_validations gem.' + ) + end + + def supported?(context) + context.engine == :rubocop + end + + def rules(_context) + LintRoller::Rules.new( + type: :path, + config_format: :rubocop, + value: File.join(__dir__, '..', '..', '..', 'config', 'rubocop-default.yml') + ) + end + end + end +end diff --git a/spec/rubocop/spec_helper.rb b/spec/rubocop/spec_helper.rb index e504a21..678249a 100644 --- a/spec/rubocop/spec_helper.rb +++ b/spec/rubocop/spec_helper.rb @@ -1,4 +1,4 @@ -require 'rubocop' +require 'rubocop-database_validations' require 'rubocop/rspec/support' require 'database_validations/rubocop/cops'