Sha256: f038e87c5b78f51d9c94354ea076d1a7de61b5add8e03141e8faf7628142304a
Contents?: true
Size: 1.13 KB
Versions: 2
Compression:
Stored size: 1.13 KB
Contents
# encoding: utf-8 module RuboCop module Cop module Style # Checks if uses of quotes match the configured preference. class StringLiterals < Cop include ConfigurableEnforcedStyle include StringLiteralsHelp def on_dstr(node) # A dstr node with dstr and str children is a concatenated # string. Don't ignore the whole thing. return if node.children.find { |child| child.type == :str } # Dynamic strings can not use single quotes, and quotes inside # interpolation expressions are checked by the # StringLiteralsInInterpolation cop, so ignore. ignore_node(node) end private def message(*) if style == :single_quotes "Prefer single-quoted strings when you don't need string " \ 'interpolation or special symbols.' else 'Prefer double-quoted strings unless you need single quotes to ' \ 'avoid extra backslashes for escaping.' end end def offense?(node) wrong_quotes?(node, style) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.27.1 | lib/rubocop/cop/style/string_literals.rb |
rubocop-0.27.0 | lib/rubocop/cop/style/string_literals.rb |