-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Format ExprIfExp (ternary operator) #5597
Conversation
d320220
to
519076c
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
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.
The jaccard index on django afterwards is 0.915.
What was the value before?
I think it could make sense to give it a quick try to add the if
and else
tokens to the SimpleTokenizer
.
/// Looks for a multi char token in the range that contains no other tokens. `SimpleTokenizer` only | ||
/// works with single char tokens so we check that we have the right token by string comparison. |
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.
It should be possible to add support for if
and else
. Comments are already non-single
token strings.
The backwards lexing is a bit more annoying but should be doable as well.
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 didn't want to change the single-char-ness of the tokenizer just for this PR, but if you want i can do the refactoring in another PR
|
||
if if_token.range.start() < comment.slice().start() | ||
&& comment.slice().start() < test.start() | ||
&& comment.line_position().is_end_of_line() |
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 recommend moving the line_position
check to the very top to avoid unnecessarily lexing own line comments.
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.
good point
The order for ternary operators is different than that for if statements
0.911, added it to the description |
1b825b5
to
730ebd7
Compare
I add it to my TODO list |
ooh, maybe i hadn't looked in detail but didn't consider it since it only has "special" chars so far, no words |
i took a stab at it: #5610 |
Summary
Format
ExprIfExp
, also known as the ternary operator or inlineif
. It can look likebut also
This also fixes a visitor order bug.
The jaccard index on django goes from 0.911 to 0.915.
Test Plan
I added fixtures without and with comments in strange places.