lib/rubocop/cop/style/word_array.rb in rubocop-0.58.2 vs lib/rubocop/cop/style/word_array.rb in rubocop-0.59.0
- old
+ new
@@ -79,14 +79,26 @@
def word_regex
Regexp.new(cop_config['WordRegex'])
end
def correct_bracketed(node)
- words = node.children.map { |w| to_string_literal(w.children[0]) }
+ words = node.children.map do |word|
+ if word.dstr_type?
+ string_literal = to_string_literal(word.source)
+ trim_string_interporation_escape_character(string_literal)
+ else
+ to_string_literal(word.children[0])
+ end
+ end
+
lambda do |corrector|
corrector.replace(node.source_range, "[#{words.join(', ')}]")
end
+ end
+
+ def trim_string_interporation_escape_character(str)
+ str.gsub(/\\\#{(.*?)\}/) { "\#{#{Regexp.last_match(1)}}" }
end
end
end
end
end