Skip to content

Commit

Permalink
Move rubocop:disable comments out of documentation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sambostock authored and marcandre committed Jun 20, 2024
1 parent e55aa21 commit d26a5e9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
4 changes: 1 addition & 3 deletions lib/rubocop/ast/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/ast/node_pattern/compiler/binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +63,6 @@ def union_bind(enum)

result
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

private

Expand Down
5 changes: 2 additions & 3 deletions lib/rubocop/ast/node_pattern/compiler/sequence_subcompiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -413,7 +413,6 @@ def merge_forks!(forks)
@in_sync = sub_compilers.all?(&:in_sync)
end
end
# rubocop:enable Metrics/ClassLength
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/ast/processed_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -345,4 +342,3 @@ def source_range(range_or_node)
end
end
end
# rubocop:enable Metrics/ClassLength

0 comments on commit d26a5e9

Please sign in to comment.