Module: RuboCop::Cop::PercentLiteral
- Included in:
- Lint::PercentStringArray, Lint::PercentSymbolArray, Style::PercentLiteralDelimiters, Style::PercentQLiterals, Style::SpaceInsideArrayPercentLiteral, Style::SpaceInsidePercentLiteralDelimiters, Style::UnneededCapitalW, Style::UnneededInterpolation
- Defined in:
- lib/rubocop/cop/mixin/percent_literal.rb
Overview
Common functionality for handling percent literals.
Instance Method Summary collapse
- #begin_source(node) ⇒ Object
-
#contents_range(node) ⇒ Object
A range containing only the contents of the percent literal (e.g. in %i2 3 this will be the range covering ‘1 2 3’ only).
- #percent_literal?(node) ⇒ Boolean
- #process(node, *types) ⇒ Object
- #type(node) ⇒ Object
Instance Method Details
#begin_source(node) ⇒ Object
17 18 19 |
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 17 def begin_source(node) node.loc.begin.source if node.loc.respond_to?(:begin) && node.loc.begin end |
#contents_range(node) ⇒ Object
A range containing only the contents of the percent literal (e.g. in %i2 3 this will be the range covering ‘1 2 3’ only)
27 28 29 |
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 27 def contents_range(node) range_between(node.loc.begin.end_pos, node.loc.end.begin_pos) end |
#percent_literal?(node) ⇒ Boolean
7 8 9 10 |
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 7 def percent_literal?(node) return unless (begin_source = begin_source(node)) begin_source.start_with?('%') end |
#process(node, *types) ⇒ Object
12 13 14 15 |
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 12 def process(node, *types) return unless percent_literal?(node) && types.include?(type(node)) on_percent_literal(node) end |
#type(node) ⇒ Object
21 22 23 |
# File 'lib/rubocop/cop/mixin/percent_literal.rb', line 21 def type(node) node.loc.begin.source[0..-2] end |