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

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
ClassCommentAlignment, DataClassMatcher, FileFilter
Defined in:
lib/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rb,
sig/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rbs

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 =

Returns:

  • (::String)
"Misaligned inline type annotation for Data attribute."

Constants included from FileFilter

FileFilter::MAGIC_COMMENT_DISABLED, FileFilter::MAGIC_COMMENT_ENABLED, FileFilter::SUPPORTED_MODES

Instance Method Summary collapse

Methods included from DataClassMatcher

#struct_like_class?

Methods included from ClassCommentAlignment

#check_annotation_alignment, #check_comment_alignment, #correct_alignment

Methods included from DataStructHelper

#annotation_column, #attr_argument?, #attr_arguments, #build_multiline_replacement, #find_regular_comment, #folded?, #inline_type_annotation?, #inline_type_comment, #longest_argname

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

#args_node_for, #end_line, #method_parameter_list_end_line, #name_location, #source!, #value_to_sym

Methods included from FileFilter

#add_offense, #configured_mode, #on_new_investigation, #rbs_inline_disabled?, #rbs_inline_enabled?, #rbs_inline_file_skipped?, #skip_by_mode?, warn_invalid_mode

Instance Method Details

#on_send(node) ⇒ void

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


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

def on_send(node) #: void
  return unless struct_like_class?(node)

  check_comment_alignment(node)
end