typing =+ instead of += is a very sneaky typo that both eslint and typescript are okay with 😅
26 replies
@zachleat go full old car grille and normalise typing +=+ which is basically OK always
oh! eslint has `space-unary-ops` which would have alerted me—wonder if I’m missing that in my config
https://eslint.org/docs/latest/rules/space-unary-ops
(and `space-infix-ops` too! https://eslint.org/docs/latest/rules/space-infix-ops)
@zachleat From an AST perspective, it's code that humans might write; `x = +string_or_number` will coerce `string_or_number` to a number. The d3 source code uses this idiom a lot, for example.
(Obviously you might still want an eslint rule that disallows this idiom, but typescript definitely shouldn't/can't flag it imo)
@llimllib yeah, for sure. Unit tests caught the issue but it would have been nice to see an error in my editor—I don’t use that pattern in my code 👀
@zachleat Agreed, and the formatting is a dead giveaway that you didn't intend the coersion idiom.
Just tested in my editor/eslint setup, and eslint doesn't notice/flag it but prettier moves the + to the proper spot, which makes it clearer what's happening, as long as you happen to notice it.
@llimllib prettier moving the + so that the eslint rule I added doesn’t catch it would be a gnarly combo https://fediverse.zachleat.com/@zachleat/112722798334691839
tf does =+ do?
@webbureaucrat like = but also coerce to a number
@zachleat JavaScript was a mistake.