Skip to content

Commit

Permalink
Merge pull request #1368 from Earlopain/documentation-rails-version
Browse files Browse the repository at this point in the history
[Fix #1203] Insert the target rails version into docs
  • Loading branch information
koic authored Sep 25, 2024
2 parents 490e9e8 + 34ca703 commit d1b7186
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 d1b7186

Please sign in to comment.