Skip to content

Commit

Permalink
Add required Ruby version to generated cops manual
Browse files Browse the repository at this point in the history
Follow up to rubocop#7921 (comment).

This PR adds required Ruby version to cops manual generated by
`rake generate_cops_documentation`.
  • Loading branch information
koic committed May 9, 2020
1 parent db6d1d0 commit a7e3299
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rubocop/cop/mixin/target_ruby_version.rb
Expand Up @@ -4,12 +4,16 @@ module RuboCop
module Cop
# Common functionality for checking target ruby version.
module TargetRubyVersion
def required_minimum_ruby_version
@minimum_target_ruby_version
end

def minimum_target_ruby_version(version)
@minimum_target_ruby_version = version
end

def support_target_ruby_version?(version)
@minimum_target_ruby_version <= version
required_minimum_ruby_version <= version
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions manual/cops_lint.md
Expand Up @@ -657,6 +657,10 @@ end

## Lint/ErbNewArguments

!!! Note

Required Ruby version: 2.6

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.56 | -
Expand Down
4 changes: 4 additions & 0 deletions manual/cops_style.md
Expand Up @@ -2712,6 +2712,10 @@ PreferHashRocketsForNonAlnumEndingSymbols | `false` | Boolean

## Style/HashTransformKeys

!!! Note

Required Ruby version: 2.5

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Pending | No | Yes (Unsafe) | 0.80 | -
Expand Down
14 changes: 14 additions & 0 deletions tasks/cops_documentation.rake
Expand Up @@ -14,15 +14,18 @@ task generate_cops_documentation: :yard_for_generate_documentation do
cops.with_department(department).sort!
end

# rubocop:disable Metrics/AbcSize
def cops_body(config, cop, description, examples_objects, pars)
content = h2(cop.cop_name)
content << required_ruby_version(cop)
content << properties(cop.new(config))
content << "#{description}\n"
content << examples(examples_objects) if examples_objects.count.positive?
content << configurations(pars)
content << references(config, cop)
content
end
# rubocop:enable Metrics/AbcSize

def examples(examples_object)
examples_object.each_with_object(h3('Examples').dup) do |example, content|
Expand All @@ -31,6 +34,17 @@ task generate_cops_documentation: :yard_for_generate_documentation do
end
end

def required_ruby_version(cop)
return '' unless cop.respond_to?(:required_minimum_ruby_version)

<<~NOTE
!!! Note
Required Ruby version: #{cop.required_minimum_ruby_version}
NOTE
end

# rubocop:disable Metrics/MethodLength
def properties(cop_instance)
header = [
Expand Down

0 comments on commit a7e3299

Please sign in to comment.