-
Notifications
You must be signed in to change notification settings - Fork 14
Support naked braces/brackets/parens, invert labels on banner #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support naked braces/brackets/parens, invert labels on banner #89
Conversation
schneems
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High level, it looks good. I'm asking that you the character reversing logic be moved into the "who dis" class and eliminate the extra state that the Banner class.
Short term I want to merge this in. I love the banner class extraction and I think it's a step in the right direction. Long term I've want to share some context and some extra thoughts. I'll drop those thoughts in the comment section.
I'm curious on your thoughts there.
| else | ||
| "DeadEnd: Unmatched `#{missing_character}` character detected" | ||
| end | ||
| when :unmatched_syntax |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm realizing that unmatched_syntax and unexpected_syntax are very similar. I'm thinking that we should make them more unique at a glance maybe missing_symbol and unexpected_syntax ? What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually scratch that, If we normalize and reverse characters in "who dis" instead then we won't need to add this extra state. I would prefer it that way instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! There's still one reversal I do here, in missing_character to show which character might be missing, see the following example:
On 2.0 release:
➜ dead_end git:(mauro-oto/support-naked-braces-brackets-and-invert-labels) ✗ dead_end test1.rb
DeadEnd: Unmatched `]` detected
file: /Users/motonelli/Projects/dead_end/test1.rb
simplified:
1 module Hey
2 class Foo
3 def initialize
❯ 4 [1,2,3
5 end
9 end
10 end
On this branch:
➜ dead_end git:(mauro-oto/support-naked-braces-brackets-and-invert-labels) ✗ exe/dead_end test1.rb
DeadEnd: Unmatched `[` character detected
It appears a `]` is missing.
file: /Users/motonelli/Projects/dead_end/test1.rb
simplified:
1 module Hey
2 class Foo
3 def initialize
❯ 4 [1,2,3
5 end
9 end
10 end
(For the It appears a ']' is missing. message, which is part of the banner)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, works for me
| "DeadEnd: Unmatched `#{@invalid_obj.unmatched_symbol}` detected" | ||
| end | ||
| end | ||
| Banner.new(invalid_obj: @invalid_obj).call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this. Extracting this logic to it's own class makes so much more sense.
|
Long-term context and thoughts. Context
(See how it complains about unexpected
Thoughts moving forwardLong term I think we need to:
I'm sure when we start doing this there will be new syntax errors we weren't expecting like: We can handle the ones that make sense, and fall back on the parser's error message for ones we don't explicitly annotate. Far far futureHere's an example of rust output showing multiple problems (that are all related), rust-lang/rust@dc003dd#diff-48cbc5a282328584a4a369f01e7c3fd128b2aa9f47869f0d04048795963530c9. I think long-long term it would be really cool to start being able to not just suggest "you need a bracket to make this code happy" but to inspect the code, find the commas, and suggest the bracket go there. Before we can get there we need to get the "here's why your code is failing" suggestion logic to be rock-solid. |
|
|
||
| expect( | ||
| DeadEnd.invalid_type(source).unmatched_symbol | ||
| ).to eq(:"[") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schneems I realized this was wrong even in the previous commit, now it shows up correctly "reversed", as shown in https://github.com/zombocom/dead_end/pull/89/files#r731862726, shows the symbol that failed to match, and what the missing character could be.
Co-authored-by: Mauro Otonelli <mauro.otonelli@gmail.com>
schneems
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome sauce, thanks!
Added support for some cases where the label is not shown, specifically when
using "naked" braces/brackets, see #84
Extracted a
Bannerclass, based on#85, and corrected the labels to
show the right matching/non-matching character.