Skip to content
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

Disable Elvis ligature (?:) for optional TypeScript properties #970

Closed
Peeja opened this issue Mar 11, 2020 · 7 comments
Closed

Disable Elvis ligature (?:) for optional TypeScript properties #970

Peeja opened this issue Mar 11, 2020 · 7 comments
Labels
Milestone

Comments

@Peeja
Copy link

Peeja commented Mar 11, 2020

I don't know languages where ?: is used as an operator well, but in TypeScript the sequence comes up a lot in interfaces, denoting optional properties in an interface:

image

The two characters don't form an operator here, they just happen to be next to each other, so the ligature is odd. Is ?: always (or at least usually) surrounded by spaces when it's used as an operator? Maybe it would work to only apply the ligature to :?, with the preceding space? (I don't have much experience with ligatures like this, so I have no idea if I'm asking for something reasonable.)

@tonsky
Copy link
Owner

tonsky commented Mar 12, 2020

Interesting! I’ll mark it as a conflict but I’m not sure what can I do, except removing ligature altogether

@jdreesen
Copy link

It's used as ternary if operator in PHP. Spaces are not required.

@Peeja
Copy link
Author

Peeja commented Mar 12, 2020

@jdreesen Wouldn't that be foo ? bar : baz? That's not going to use the ?: ligature.

@j-f1
Copy link
Contributor

j-f1 commented Mar 12, 2020

I know some languages (C?) use a ?: b as shorthand for a ? a : b or how a || b works in some languages.

@jdreesen
Copy link

jdreesen commented Mar 13, 2020

@jdreesen Wouldn't that be foo ? bar : baz? That's not going to use the ?: ligature.

Right, but you can do $foo ?: $baz as shorthand, which returns $foo if $foo evaluates to true, and $baz otherwise. Example: https://3v4l.org/8H95j

@tonsky tonsky added this to the 3 milestone Apr 8, 2020
@tonsky tonsky closed this as completed in 76a6d42 Apr 8, 2020
@KyNorthstar
Copy link

KyNorthstar commented Apr 9, 2020

Sad to see this go (I use it a lot in Kotlin, ObjC, and others), but I understand why it did

@a-p-o
Copy link

a-p-o commented Apr 11, 2020

Kotlin uses ?: (elvis operator). It is conventionally surrounded by spaces. This is an unfortunate change for Kotlin users 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants