Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upProposal: conditional operator in string concatenation #893
Comments
This comment has been minimized.
This comment has been minimized.
|
Think when concatenating constants it might make sense that it's indeed not
what you want. If it uses vars it's a v different case. A specific rule for
this could indeed be helpful
…On Tue, May 23, 2017, 18:19 Tomas Della Vedova ***@***.***> wrote:
Hi all! :)
I got this weird issue that was not trivial to debug until I found the
cause.
If you use a conditional operator without the parenthesis inside a string
concatenation the result will not be what you are expecting (at least for
me!).
Example:
'hello' + true ? 'a' : 'b' + 'world' // 'a'
'hello' + (true ? 'a' :'b') + 'world' // 'helloaworld'
Standard didn't warn me about this behaviour, it is worth make a new rule?
Thanks!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#893>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWleii4t9psyv_DFSc7OZSPAFTq9ja5ks5r8wcqgaJpZM4Nj8fS>
.
|
This comment has been minimized.
This comment has been minimized.
|
Happens the same if I do: var h = 'hello'
var w = 'world'
console.log(h + true ? 'a' : 'b' + w) // 'a'
console.log(h + (true ? 'a' : 'b') + w) // 'helloaworld' |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the suggestion. There's not an ESLint rule to catch this case, as far as I'm aware. But I'll keep my eyes out for if one gets added and enable it. |
feross
closed this
Apr 21, 2018
This comment has been minimized.
This comment has been minimized.
|
Great, and thank you this awesome project! :) |
lock
bot
locked as resolved and limited conversation to collaborators
Jul 21, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
delvedor commentedMay 23, 2017
Hi all! :)
I got this weird issue that was not trivial to debug until I found the cause.
If you use a conditional operator without the parenthesis inside a string concatenation the result will not be what you are expecting (at least for me!).
Example:
Standard didn't warn me about this behaviour, it is worth make a new rule?
Thanks!