From af7fed62a2f052cdb507be83a73c6e73126a492c Mon Sep 17 00:00:00 2001 From: Alfonso Uceda Date: Mon, 30 Mar 2026 16:43:47 +0200 Subject: [PATCH 1/3] LintRoller plugin, rather than Inject monkey-patch RuboCop 1.72+ supports a formal plugin system via LintRoller::Plugin. This replaces the old Inject.defaults! approach that monkey-patched ConfigLoader with a proper Plugin class that declares its config through the LintRoller API. - Add lib/rubocop/granite/plugin.rb - Remove lib/rubocop/granite/inject.rb - Bump minimum rubocop to >= 1.72.1 - Add lint_roller ~> 1.1 dependency - Add default_lint_roller_plugin gemspec metadata - Update README to use plugins: instead of require: --- README.md | 9 ++++++--- granite.gemspec | 3 ++- lib/rubocop-granite.rb | 4 +--- lib/rubocop/granite.rb | 5 ----- lib/rubocop/granite/inject.rb | 18 ------------------ lib/rubocop/granite/plugin.rb | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 41 insertions(+), 30 deletions(-) delete mode 100644 lib/rubocop/granite/inject.rb create mode 100644 lib/rubocop/granite/plugin.rb diff --git a/README.md b/README.md index 4a59a3be..dfaf7516 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,13 @@ rspec Add this to your Rubocop config file: +```yaml +plugins: + - granite: + require_path: rubocop-granite ``` -require: - - rubocop-granite -``` + +The plugin system requires RuboCop 1.72+. For earlier versions, use `require: rubocop-granite` instead. This will add config for `Lint/UselessAccessModifier` to treat `projector` as separate context. It is equivalent to: diff --git a/granite.gemspec b/granite.gemspec index d2f7a7ee..4ddd7481 100644 --- a/granite.gemspec +++ b/granite.gemspec @@ -28,11 +28,12 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec-its' s.add_development_dependency 'rspec_junit_formatter' s.add_development_dependency 'rspec-rails' - s.add_development_dependency 'rubocop' + s.add_development_dependency 'rubocop', '>= 1.72.1' s.add_development_dependency 'rubocop-rails' s.add_development_dependency 'rubocop-rspec' s.add_development_dependency 'rubocop-rspec_rails' s.add_development_dependency 'simplecov' + s.metadata['default_lint_roller_plugin'] = 'RuboCop::Granite::Plugin' s.metadata['rubygems_mfa_required'] = 'true' end diff --git a/lib/rubocop-granite.rb b/lib/rubocop-granite.rb index 0b8720cd..d46fca39 100644 --- a/lib/rubocop-granite.rb +++ b/lib/rubocop-granite.rb @@ -1,6 +1,4 @@ require 'rubocop' require_relative 'rubocop/granite' -require_relative 'rubocop/granite/inject' - -RuboCop::Granite::Inject.defaults! +require_relative 'rubocop/granite/plugin' diff --git a/lib/rubocop/granite.rb b/lib/rubocop/granite.rb index bedebc9d..62a1e8e0 100644 --- a/lib/rubocop/granite.rb +++ b/lib/rubocop/granite.rb @@ -1,9 +1,4 @@ module RuboCop module Granite # :nodoc: - PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze - CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'rubocop-default.yml').freeze - CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze - - private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT) end end diff --git a/lib/rubocop/granite/inject.rb b/lib/rubocop/granite/inject.rb deleted file mode 100644 index 03e53b91..00000000 --- a/lib/rubocop/granite/inject.rb +++ /dev/null @@ -1,18 +0,0 @@ -# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb -# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md -module RuboCop - module Granite - # Because RuboCop doesn't yet support plugins, we have to monkey patch in a - # bit of our configuration. - module Inject - def self.defaults! - path = CONFIG_DEFAULT.to_s - hash = ConfigLoader.load_file(path) - config = Config.new(hash, path).tap(&:make_excludes_absolute) - Rails.logger.debug { "configuration from #{path}" } if ConfigLoader.debug? - config = ConfigLoader.merge_with_default(config, path) - ConfigLoader.instance_variable_set(:@default_configuration, config) - end - end - end -end diff --git a/lib/rubocop/granite/plugin.rb b/lib/rubocop/granite/plugin.rb new file mode 100644 index 00000000..e2818ba0 --- /dev/null +++ b/lib/rubocop/granite/plugin.rb @@ -0,0 +1,32 @@ +require 'lint_roller' +require 'granite/version' + +module RuboCop + module Granite + # Plugin integration for RuboCop's plugin system (1.72+). + class Plugin < LintRoller::Plugin + def about + LintRoller::About.new( + name: 'rubocop-granite', + version: ::Granite::VERSION, + homepage: 'https://github.com/toptal/granite', + description: 'Custom RuboCop configuration for Granite' + ) + end + + def supported?(context) + context.engine == :rubocop + end + + def rules(_context) + project_root = Pathname.new(__dir__).parent.parent.parent.expand_path + + LintRoller::Rules.new( + type: :path, + config_format: :rubocop, + value: project_root.join('config', 'rubocop-default.yml').to_s + ) + end + end + end +end From 505e3f4d40023c14af0e73ea408fa53d31aa79ae Mon Sep 17 00:00:00 2001 From: Alfonso Uceda Date: Mon, 30 Mar 2026 17:37:01 +0200 Subject: [PATCH 2/3] Defunct Travis CI badge is removed --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index dfaf7516..891c1e6c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Granite is an alternative Rails application architecture framework. -[![Build Status](https://travis-ci.org/toptal/granite.svg?branch=master)](https://travis-ci.org/toptal/granite) - ## Installation Add this line to your application's Gemfile: From 8e3ae24aad1203cd98e64d683322f91c2909de9a Mon Sep 17 00:00:00 2001 From: Alfonso Uceda Date: Mon, 30 Mar 2026 17:37:31 +0200 Subject: [PATCH 3/3] CI workflow, rather than Ruby Renamed for consistency with rubocop-toptal. --- .github/workflows/{ruby.yml => ci.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{ruby.yml => ci.yml} (99%) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ci.yml similarity index 99% rename from .github/workflows/ruby.yml rename to .github/workflows/ci.yml index bb3bf98d..ea0ff46b 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby -name: Ruby +name: CI on: push: