From a7e3299d3e7e1bd0c4d16f95f5b9cfc121456596 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 10 May 2020 01:36:53 +0900 Subject: [PATCH] Add required Ruby version to generated cops manual Follow up to https://github.com/rubocop-hq/rubocop/pull/7921#discussion_r422328979. This PR adds required Ruby version to cops manual generated by `rake generate_cops_documentation`. --- lib/rubocop/cop/mixin/target_ruby_version.rb | 6 +++++- manual/cops_lint.md | 4 ++++ manual/cops_style.md | 4 ++++ tasks/cops_documentation.rake | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/rubocop/cop/mixin/target_ruby_version.rb b/lib/rubocop/cop/mixin/target_ruby_version.rb index 6ec4f369db5..11b82d6dc5c 100644 --- a/lib/rubocop/cop/mixin/target_ruby_version.rb +++ b/lib/rubocop/cop/mixin/target_ruby_version.rb @@ -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 diff --git a/manual/cops_lint.md b/manual/cops_lint.md index 9693297739d..ecbe9febb25 100644 --- a/manual/cops_lint.md +++ b/manual/cops_lint.md @@ -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 | - diff --git a/manual/cops_style.md b/manual/cops_style.md index dacc165e830..056eb74509f 100644 --- a/manual/cops_style.md +++ b/manual/cops_style.md @@ -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 | - diff --git a/tasks/cops_documentation.rake b/tasks/cops_documentation.rake index 77a3bf9b2af..a5fd576f24d 100644 --- a/tasks/cops_documentation.rake +++ b/tasks/cops_documentation.rake @@ -14,8 +14,10 @@ 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? @@ -23,6 +25,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do 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| @@ -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 = [