Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.0.3

- Fix: Correctly identify trailing slashes when using Prism > 1.8.0. (https://github.com/ruby/syntax_suggest/pull/243)
- Fix: Correctly handle `%I` delimiters. (https://github.com/ruby/syntax_suggest/pull/249)
- Internal: Add tests to multiple versions of prism

## 2.0.2
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax_suggest/left_right_lex_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def count_lex(lex)
# Means it's a string or a symbol `"{"` rather than being
# part of a data structure (like a hash) `{ a: b }`
# ignore it.
when :on_words_beg, :on_symbos_beg, :on_qwords_beg,
when :on_words_beg, :on_symbols_beg, :on_qwords_beg,
:on_qsymbols_beg, :on_regexp_beg, :on_tstring_beg
# ^^^
# Handle shorthand syntaxes like `%Q{ i am a string }`
Expand Down
32 changes: 30 additions & 2 deletions spec/unit/explain_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@ module SyntaxSuggest
expect(explain.errors.join.strip).to_not be_empty
end

it "handles %w[]" do
%w[w W i I].each do |type|
it "handles %#{type}-style array" do
source = <<~EOM
node.is_a?(Op) && %#{type}[| ||].include?(node.value) &&
EOM

explain = ExplainSyntax.new(
code_lines: CodeLine.from_source(source)
).call

expect(explain.missing).to eq([])
end
end

it "handles %r-style regexp" do
source = <<~EOM
node.is_a?(Op) && %w[| ||].include?(node.value) &&
node.is_a?(Op) && %r{| ||}.include?(node.value) &&
EOM

explain = ExplainSyntax.new(
Expand All @@ -29,6 +43,20 @@ module SyntaxSuggest
expect(explain.missing).to eq([])
end

["", "q", "Q"].each do |type|
it "handles %#{type}-style string" do
source = <<~EOM
node.is_a?(Op) && %#{type}(| ||).include?(node.value) &&
EOM

explain = ExplainSyntax.new(
code_lines: CodeLine.from_source(source)
).call

expect(explain.missing).to eq([])
end
end

it "doesn't falsely identify strings or symbols as critical chars" do
source = <<~EOM
a = ['(', '{', '[', '|']
Expand Down