Skip to content
This repository was archived by the owner on Aug 1, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/tailor/rulers/allow_unnecessary_double_quotes_ruler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def initialize(config, options)
def nl_update(lexed_line, lineno, _)
quotes(lexed_line).each do |quote|
unless contains_embedded_expression?(quote) ||
contains_escape_sequence?(quote)
contains_escape_sequence?(quote) ||
contains_single_quote?(quote)
measure(lineno, column(quote.first))
end
end
Expand Down Expand Up @@ -39,6 +40,12 @@ def contains_escape_sequence?(tokens)
end
end

def contains_single_quote?(tokens)
tokens.any? do |t|
t[1] == :on_tstring_content and t[2].match(/'/)
end
end

def quotes(tokens)
tokens.select do |t|
true if (double_quote_start?(t))..(double_quote_end?(t))
Expand Down
7 changes: 7 additions & 0 deletions spec/functional/string_quoting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def contents
end
end

context :double_quotes_contains_single_quote do
it 'does not warn' do
critic.check_file(file_name, style.to_hash)
expect(critic.problems[file_name]).to be_empty
end
end

context :escape_sequence do
it 'does not warn when a double quoted string contains a newline' do
critic.check_file(file_name, style.to_hash)
Expand Down
4 changes: 4 additions & 0 deletions spec/support/string_quoting_cases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
QUOTING['nested_quotes'] =
%q{foo = "foo#{bar('baz')}"
}

QUOTING['double_quotes_contains_single_quote'] =
%q{foo = "foo'd"
}