Module: RuboCop::Cop::EndKeywordAlignment
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Defined in: | lib/rubocop/cop/mixin/end_keyword_alignment.rb |
Overview
Functions for checking the alignment of the end
keyword.
Constant Summary
-
MSG =
# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 10'`end` at %<end_line>d, %<end_col>d is not aligned with ' \ '`%<source>s` at %<align_line>d, %<align_col>d.'
ConfigurableEnforcedStyle
- Included
RangeHelp
- Included
Instance Attribute Summary
ConfigurableEnforcedStyle
- Included
Instance Method Summary
- #accept_end_kw_alignment?(end_loc) ⇒ Boolean private
- #add_offense_for_misalignment(node, align_with) private
- #check_end_kw_alignment(node, align_ranges) private
- #check_end_kw_in_node(node) private
- #line_break_before_keyword?(whole_expression, rhs) ⇒ Boolean private
- #matching_ranges(end_loc, align_ranges) private
- #start_line_range(node) private
- #style_parameter_name private
- #variable_alignment?(whole_expression, rhs, end_alignment_style) ⇒ Boolean private
RangeHelp
- Included
#add_range, #column_offset_between, | |
#contents_range | A range containing only the contents of a literal with delimiters (e.g. |
#directions, | |
#effective_column | Returns the column attribute of the range, except if the range is on the first line and there’s a byte order mark at the beginning of that line, in which case 1 is subtracted from the column value. |
#final_pos, #move_pos, #move_pos_str, #range_between, #range_by_whole_lines, #range_with_comments, #range_with_comments_and_lines, #range_with_surrounding_comma, #range_with_surrounding_space, #source_range |
ConfigurableEnforcedStyle
- Included
Instance Method Details
#accept_end_kw_alignment?(end_loc) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 60
def accept_end_kw_alignment?(end_loc) end_loc.nil? || # Discard modifier forms of if/while/until. !/\A[ \t]*end/.match?(processed_source.lines[end_loc.line - 1]) end
#add_offense_for_misalignment(node, align_with) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 50
def add_offense_for_misalignment(node, align_with) end_loc = node.loc.end msg = format(MSG, end_line: end_loc.line, end_col: end_loc.column, source: align_with.source, align_line: align_with.line, align_col: align_with.column) add_offense(end_loc, message: msg) { |corrector| autocorrect(corrector, node) } end
#check_end_kw_alignment(node, align_ranges) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 19
def check_end_kw_alignment(node, align_ranges) return if ignored_node?(node) end_loc = node.loc.end return if accept_end_kw_alignment?(end_loc) matching = matching_ranges(end_loc, align_ranges) if matching.key?(style) correct_style_detected else add_offense_for_misalignment(node, align_ranges[style]) style_detected(matching.keys) end end
#check_end_kw_in_node(node) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 15
def check_end_kw_in_node(node) check_end_kw_alignment(node, style => node.loc.keyword) end
#line_break_before_keyword?(whole_expression, rhs) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 75
def line_break_before_keyword?(whole_expression, rhs) rhs.first_line > whole_expression.line end
#matching_ranges(end_loc, align_ranges) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 35
def matching_ranges(end_loc, align_ranges) align_ranges.select do |_, range| same_line?(range, end_loc) || column_offset_between(range, end_loc).zero? end end
#start_line_range(node) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 41
def start_line_range(node) expr = node.source_range buffer = expr.source_buffer source = buffer.source_line(expr.line) range = buffer.line_range(expr.line) range_between(range.begin_pos + (source =~ /\S/), range.begin_pos + (source =~ /\s*\z/)) end
#style_parameter_name (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 65
def style_parameter_name 'EnforcedStyleAlignWith' end
#variable_alignment?(whole_expression, rhs, end_alignment_style) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/mixin/end_keyword_alignment.rb', line 69
def variable_alignment?(whole_expression, rhs, end_alignment_style) return false if end_alignment_style == :keyword !line_break_before_keyword?(whole_expression, rhs) end