From cb3c0cf49187eaff9642306c2ae280920c765650 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:52:17 +0200 Subject: [PATCH] [Fix #1203] Insert the target rails version into docs --- lib/rubocop/cop/mixin/target_rails_version.rb | 8 +++----- tasks/cops_documentation.rake | 9 ++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/rubocop/cop/mixin/target_rails_version.rb b/lib/rubocop/cop/mixin/target_rails_version.rb index 4dca5074ae..a6eb55052c 100644 --- a/lib/rubocop/cop/mixin/target_rails_version.rb +++ b/lib/rubocop/cop/mixin/target_rails_version.rb @@ -7,6 +7,9 @@ module TargetRailsVersion # Informs the base RuboCop gem that it the Rails version is checked via `requires_gem` API, # without needing to call this `#support_target_rails_version` method. USES_REQUIRES_GEM_API = true + # Look for `railties` instead of `rails`, to support apps that only use a subset of `rails` + # See https://github.com/rubocop/rubocop/pull/11289 + TARGET_GEM_NAME = 'railties' # :nodoc: def minimum_target_rails_version(version) if respond_to?(:requires_gem) @@ -33,11 +36,6 @@ def support_target_rails_version?(version) @minimum_target_rails_version <= version end end - - # Look for `railties` instead of `rails`, to support apps that only use a subset of `rails` - # See https://github.com/rubocop/rubocop/pull/11289 - TARGET_GEM_NAME = 'railties' - private_constant :TARGET_GEM_NAME end end end diff --git a/tasks/cops_documentation.rake b/tasks/cops_documentation.rake index 7d9275354e..3804b175ee 100644 --- a/tasks/cops_documentation.rake +++ b/tasks/cops_documentation.rake @@ -12,12 +12,19 @@ end task update_cops_documentation: :yard_for_generate_documentation do deps = ['Rails'] + # NOTE: Insert minimum_target_rails_version after ruby version + required_rails_version = lambda do |data| + return '' unless (version = data.cop.gem_requirements[RuboCop::Cop::TargetRailsVersion::TARGET_GEM_NAME]) + + "NOTE: Required Rails version: #{version.requirements[0][1]}\n\n" + end + extra_info = { required_ruby_version: required_rails_version } # NOTE: Update `<>` version for docs/modules/ROOT/pages/cops_rails.adoc # when running release tasks. RuboCop::Rails::Inject.defaults! - CopsDocumentationGenerator.new(departments: deps).call + CopsDocumentationGenerator.new(departments: deps, extra_info: extra_info).call end desc 'Syntax check for the documentation comments'