Skip to content

Commit

Permalink
[Fix #1203] Insert the target rails version into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Sep 19, 2024
1 parent f935a0b commit cb3c0cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 3 additions & 5 deletions lib/rubocop/cop/mixin/target_rails_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
9 changes: 8 additions & 1 deletion tasks/cops_documentation.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<<next>>` 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'
Expand Down

0 comments on commit cb3c0cf

Please sign in to comment.