Module: RuboCop::Cop::SpaceBeforePunctuation
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
RangeHelp
|
|
| Defined in: | lib/rubocop/cop/mixin/space_before_punctuation.rb |
Overview
Common functionality for cops checking for space before punctuation.
Constant Summary
-
MSG =
# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 10'Space found before %<token>s.' -
SPACE_INSIDE_PARENS_STYLES =
# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 11%w[space compact].freeze
RangeHelp - Included
Instance Attribute Summary
- #space_required_after_lcurly? ⇒ Boolean readonly private
- #space_required_after_lparen? ⇒ Boolean readonly private
Instance Method Summary
- #on_new_investigation
- #each_missing_space(tokens) private
- #space_missing?(token1, token2) ⇒ Boolean private
- #space_required_after?(token) ⇒ Boolean private
RangeHelp - Included
| #add_range, | |
| #arguments_range | A range containing the first to the last argument of a method call or method definition. |
| #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 | rubocop:disable-next Metrics/ParameterLists. |
| #move_pos, #move_pos_str, #range_between, #range_by_whole_lines, | |
| #range_for_statement_removal | Returns the range to remove a statement: its whole lines, including a trailing comment and the final newline, when no other code shares them, and otherwise the range itself with the spaces after it. |
| #range_with_comments, #range_with_comments_and_lines, #range_with_surrounding_comma, #range_with_surrounding_space, #source_range | |
Instance Attribute Details
#space_required_after_lcurly? ⇒ Boolean (readonly, private)
[ GitHub ]
# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 46
def space_required_after_lcurly? cfg = config.for_cop('Layout/SpaceInsideBlockBraces') style = cfg['EnforcedStyle'] || 'space' style == 'space' end
#space_required_after_lparen? ⇒ Boolean (readonly, private)
[ GitHub ]
# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 52
def space_required_after_lparen? style = config.for_enabled_cop('Layout/SpaceInsideParens')['EnforcedStyle'] SPACE_INSIDE_PARENS_STYLES.include?(style) end
Instance Method Details
#each_missing_space(tokens) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 23
def each_missing_space(tokens) tokens.each_cons(2) do |token1, token2| next unless kind(token2) next unless space_missing?(token1, token2) next if space_required_after?(token1) pos_before_punctuation = range_between(token1.end_pos, token2.begin_pos) yield token2, pos_before_punctuation end end
#on_new_investigation
[ GitHub ]# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 13
def on_new_investigation each_missing_space(processed_source.sorted_tokens) do |token, pos_before| add_offense(pos_before, message: format(MSG, token: kind(token))) do |corrector| PunctuationCorrector.remove_space(corrector, pos_before) end end end
#space_missing?(token1, token2) ⇒ Boolean (private)
# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 35
def space_missing?(token1, token2) same_line?(token1, token2) && token2.begin_pos > token1.end_pos end
#space_required_after?(token) ⇒ Boolean (private)
# File 'lib/rubocop/cop/mixin/space_before_punctuation.rb', line 39
def space_required_after?(token) return space_required_after_lcurly? if token.left_curly_brace? return space_required_after_lparen? if token.left_parens? false end