Class: RuboCop::Cop::Style::RbsInline::DataClassCommentAlignment

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp, ASTUtils, SourceCodeHelper
Defined in:
lib/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rb

Overview

Checks that ‘#:` inline type annotations in `Data.define` blocks are aligned.

Each ‘#:` annotation comment should start at the same column, determined by the longest attribute name (plus trailing comma). Folded `Data.define` calls (where attributes are not one per line) are excluded.

Examples:

# bad
MethodEntry = Data.define(
  :name, #: Symbol
  :node,       #: Parser::AST::Node
  :visibility  #: Symbol
)

# good
MethodEntry = Data.define(
  :name,       #: Symbol
  :node,       #: Parser::AST::Node
  :visibility  #: Symbol
)

Constant Summary collapse

MSG =
'Misaligned inline type annotation for Data attribute.'

Instance Method Summary collapse

Methods included from SourceCodeHelper

#annotation_range, #blank_line?, #char_at, #character_offset, #comment_at, #comment_range, #line_range, #location_to_range, #source_code_at

Methods included from ASTUtils

#end_line, #name_location, #source!, #value_to_sym

Instance Method Details

#on_send(node) ⇒ Object



37
38
39
40
41
42
# File 'lib/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rb', line 37

def on_send(node) #: void
  return unless data_define?(node)
  return if folded_data_class?(node)

  check_annotation_alignment(node)
end