Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (unreleased)

- Fix explanation involving shorthand syntax for literals like `%w[]` and `%Q{}` (https://github.com/zombocom/dead_end/pull/116)

## 3.0.2

- Fix windows filename detection (https://github.com/zombocom/dead_end/pull/114)
Expand Down
11 changes: 11 additions & 0 deletions lib/dead_end/left_right_lex_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ 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,
:on_qsymbols_beg, :on_regexp_beg, :on_tstring_beg
# ^^^
# Handle shorthand syntaxes like `%Q{ i am a string }`
#
# The start token will be the full thing `%Q{` but we
# need to count it as if it's a `{`. Any token
# can be used
char = lex.token[-1]
@count_for_char[char] += 1 if @count_for_char.key?(char)
when :on_embexpr_beg
# ^^^
# Embedded string expressions like `"#{foo} <-embed"`
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/explain_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

module DeadEnd
RSpec.describe "ExplainSyntax" do
it "handles %w[]" do
source = <<~EOM
node.is_a?(Op) && %w[| ||].include?(node.value) &&
EOM

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

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

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