Skip to content

Conversation

@mauro-oto
Copy link
Contributor

@mauro-oto mauro-oto commented Feb 13, 2021

Consider tIDENTIFIER in Ruby 2.6 and local variable or method in Ruby 2.7 and 3.0

dead_end was showing just the syntax error, but not the banner:

➜   dead_end datadog.rb

file: /Users/mauro-oto/Projects/dead_end/datadog.rb
simplified:

       4  Datadog.configure do |c|
    ❯  5    ["rails", "grpc"].each do |service
    ❯ 11    end
      12  end

With the fix:

➜  dead_end datadog.rb

DeadEnd: Unmatched `|` character detected

Example:

  `do |x` should be `do |x|`

file: /Users/mauro-oto/Projects/dead_end/datadog.rb
simplified:

       4  Datadog.configure do |c|
    ❯  5    ["rails", "grpc"].each do |service
    ❯ 11    end
      12  end

@mauro-oto mauro-oto requested a review from schneems February 13, 2021 03:42
`tIDENTIFIER` in Ruby 2.6 and `local variable or method` in Ruby 2.7 and 3.0
@mauro-oto mauro-oto force-pushed the consider-unexpected-local-variable-or-method branch from 9529fff to c484815 Compare February 13, 2021 03:45
class Blerg
Foo.call do |a
end # one
context "determines the type of syntax error to be an unmatched pipe" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schneems I noticed you are not really using context in the specs, would you prefer to keep these separate?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My experience with contexts is that they become large and unwieldy and lose their usefulness and then when tests get moved around the indentation makes the diff larger. I'm not strictly against it though.

Copy link
Collaborator

@schneems schneems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I gave one comment on an alternate implementation. Let me know what you think.

when /unexpected `end'/, # Ruby 2.7 and 3.0
/unexpected end/, # Ruby 2.6
/unexpected keyword_end/i # Ruby 2.5
when /unexpected `end'/, # Ruby 2.7 and 3.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding a case statement above the unexpected end case. Something like:

when /unexpected .* expecting '(?<unmatched_symbol>.*)/
  match = $LAST_MATCH_INFO
  @unmatched_symbol = match[:unmatched_symbol].to_sym
  @error_symbol = :unmatched_syntax

I'm wondering if that will allow us to simplify this a bit. My worry is the larger this case becomes the more likely accidentally firing this logic on an unrelated parse error becomes larger. By moving the "expecting " logic above this case in the detection, we can avoid trying to catch some of these seemingly unrelated other exception types.

Copy link
Contributor Author

@mauro-oto mauro-oto Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schneems thanks, updated! Let me know what you think.

I checked and the only one that doesn't match that regexp now is unexpected `end' so I left that one there, and the rest are covered by that new regexp now 👍

Also had to use $1 instead, because for some reason $LAST_MATCH_INFO comes back as nil 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I had to also leave the cases for 2.5 and 2.6, although we could use a regex there too.. what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, exactly what I had in mind

@schneems schneems merged commit 34f7e01 into main Feb 25, 2021
@schneems schneems deleted the consider-unexpected-local-variable-or-method branch February 25, 2021 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants