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

## 3.1.1

- Fix case where Ripper lexing identified incorrect code as a keyword (https://github.com/zombocom/dead_end/pull/122)

## 3.1.0

- Add support for Ruby 3.1 by updating `require_relative` logic (https://github.com/zombocom/dead_end/pull/120)
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
dead_end (3.1.0)
dead_end (3.1.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -62,4 +62,4 @@ DEPENDENCIES
standard

BUNDLED WITH
2.2.30
2.3.4
5 changes: 4 additions & 1 deletion lib/dead_end/lex_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def initialize(source:, source_lines: nil)
lineno = @lex.last.pos.first + 1
end

@lex.map! { |elem| LexValue.new(elem.pos.first, elem.event, elem.tok, elem.state) }
last_lex = nil
@lex.map! { |elem|
last_lex = LexValue.new(elem.pos.first, elem.event, elem.tok, elem.state, last_lex)
}
end

def to_a
Expand Down
12 changes: 9 additions & 3 deletions lib/dead_end/lex_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ module DeadEnd
class LexValue
attr_reader :line, :type, :token, :state

def initialize(line, type, token, state)
def initialize(line, type, token, state, last_lex = nil)
@line = line
@type = type
@token = token
@state = state

set_kw_end
set_kw_end(last_lex)
end

private def set_kw_end
private def set_kw_end(last_lex)
@is_end = false
@is_kw = false
return if type != :on_kw
#
return if last_lex && last_lex.fname? # https://github.com/ruby/ruby/commit/776759e300e4659bb7468e2b97c8c2d4359a2953

case token
when "if", "unless", "while", "until"
Expand All @@ -41,6 +43,10 @@ def initialize(line, type, token, state)
end
end

def fname?
state.allbits?(Ripper::EXPR_FNAME)
end

def ignore_newline?
type == :on_ignored_nl
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dead_end/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DeadEnd
VERSION = "3.1.0"
VERSION = "3.1.1"
end
12 changes: 12 additions & 0 deletions spec/unit/code_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

module DeadEnd
RSpec.describe CodeLine do
it "bug in keyword detection" do
lines = CodeLine.from_source(<<~'EOM')
def to_json(*opts)
{
type: :module,
}.to_json(*opts)
end
EOM
expect(lines.count(&:is_kw?)).to eq(1)
expect(lines.count(&:is_end?)).to eq(1)
end

it "supports endless method definitions" do
skip("Unsupported ruby version") unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3")

Expand Down