From d26a5e918b77c09adf7b6c01263597b29349497d Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Thu, 20 Jun 2024 02:41:13 -0400 Subject: [PATCH] Move `rubocop:disable` comments out of documentation When `rubocop:disable` is used immediately above a method or module declaration, it becomes part of the documentation. Instead, if we inline it with the declaration itself, it is not included in the documentation. As a side benefit, RuboCop attaches it to that declaration only, removing the need to `rubocop:enable` afterwards. However, YARD applies it as documentation to whatever immediately follows, so if the next declaration is public, we must explicitly document it, so YARD properly ignores the `rubocop:disable` comment. --- lib/rubocop/ast/node.rb | 4 +--- lib/rubocop/ast/node_pattern/compiler/binding.rb | 6 +++--- .../ast/node_pattern/compiler/sequence_subcompiler.rb | 5 ++--- lib/rubocop/ast/processed_source.rb | 8 ++------ 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/rubocop/ast/node.rb b/lib/rubocop/ast/node.rb index cf6e47c92..1818be1a3 100644 --- a/lib/rubocop/ast/node.rb +++ b/lib/rubocop/ast/node.rb @@ -557,8 +557,7 @@ def guard_clause? # So, does the return value of this node matter? If we changed it to # `(...; nil)`, might that affect anything? # - # rubocop:disable Metrics/MethodLength - def value_used? + def value_used? # rubocop:disable Metrics/MethodLength # Be conservative and return true if we're not sure. return false if parent.nil? @@ -579,7 +578,6 @@ def value_used? true end end - # rubocop:enable Metrics/MethodLength # Some expressions are evaluated for their value, some for their side # effects, and some for both. diff --git a/lib/rubocop/ast/node_pattern/compiler/binding.rb b/lib/rubocop/ast/node_pattern/compiler/binding.rb index 7f80d8396..e68e90023 100644 --- a/lib/rubocop/ast/node_pattern/compiler/binding.rb +++ b/lib/rubocop/ast/node_pattern/compiler/binding.rb @@ -26,8 +26,9 @@ def bind(name) var end - # rubocop:disable Metrics/MethodLength, Metrics/AbcSize - def union_bind(enum) + # Yields for each branch of the given union, forbidding unification of + # bindings which only appear in a subset of the union. + def union_bind(enum) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize # We need to reset @bound before each branch is processed. # Moreover we need to keep track of newly encountered wildcards. # Var `newly_bound_intersection` will hold those that are encountered @@ -62,7 +63,6 @@ def union_bind(enum) result end - # rubocop:enable Metrics/MethodLength, Metrics/AbcSize private diff --git a/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb b/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb index 08e796e69..f367a89b6 100644 --- a/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb +++ b/lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb @@ -13,8 +13,8 @@ class Compiler # Doc on how this fits in the compiling process: # /docs/modules/ROOT/pages/node_pattern.adoc # - # rubocop:disable Metrics/ClassLength - class SequenceSubcompiler < Subcompiler + class SequenceSubcompiler < Subcompiler # rubocop:disable Metrics/ClassLength + # Shift of 1 from standard Ruby indices DELTA = 1 POSITIVE = :positive?.to_proc private_constant :POSITIVE @@ -413,7 +413,6 @@ def merge_forks!(forks) @in_sync = sub_compilers.all?(&:in_sync) end end - # rubocop:enable Metrics/ClassLength end end end diff --git a/lib/rubocop/ast/processed_source.rb b/lib/rubocop/ast/processed_source.rb index 2100ae800..7aecb82f2 100644 --- a/lib/rubocop/ast/processed_source.rb +++ b/lib/rubocop/ast/processed_source.rb @@ -2,13 +2,12 @@ require 'digest/sha1' -# rubocop:disable Metrics/ClassLength module RuboCop module AST # ProcessedSource contains objects which are generated by Parser # and other information such as disabled lines for cops. # It also provides a convenient way to access source lines. - class ProcessedSource + class ProcessedSource # rubocop:disable Metrics/ClassLength # @api private STRING_SOURCE_NAME = '(string)' @@ -236,8 +235,7 @@ def tokenize(parser) [ast, comments, tokens] end - # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength - def parser_class(ruby_version, parser_engine) + def parser_class(ruby_version, parser_engine) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength case parser_engine when :parser_whitequark case ruby_version @@ -307,7 +305,6 @@ def parser_class(ruby_version, parser_engine) end end end - # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength def create_parser(ruby_version, parser_engine) builder = RuboCop::AST::Builder.new @@ -345,4 +342,3 @@ def source_range(range_or_node) end end end -# rubocop:enable Metrics/ClassLength