Module: RuboCop::Cop::StringLiteralsHelp
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubocop/cop/mixin/string_literals_help.rb |
Overview
Common functionality for cops checking single/double quotes.
Instance Attribute Summary
- #enforce_double_quotes? ⇒ Boolean readonly private
Instance Method Summary
- #preferred_string_literal private
- #string_literals_config private
- #wrong_quotes?(src_or_node) ⇒ Boolean private
Instance Attribute Details
#enforce_double_quotes? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/rubocop/cop/mixin/string_literals_help.rb', line 24
def enforce_double_quotes? string_literals_config['EnforcedStyle'] == 'double_quotes' end
Instance Method Details
#preferred_string_literal (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/string_literals_help.rb', line 20
def preferred_string_literal enforce_double_quotes? ? '""' : "''" end
#string_literals_config (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/string_literals_help.rb', line 28
def string_literals_config config.for_enabled_cop('Style/StringLiterals') end
#wrong_quotes?(src_or_node) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/mixin/string_literals_help.rb', line 9
def wrong_quotes?(src_or_node) src = src_or_node.is_a?(RuboCop::AST::Node) ? src_or_node.source : src_or_node return false if src.start_with?('%', '?') if style == :single_quotes !double_quotes_required?(src) else !/" | \\[^'\\] | \#[@{$]/x.match?(src) end end