jscs-dev / node-jscs

:arrow_heading_up: JavaScript Code Style checker (unmaintained)
https://jscs-dev.github.io
MIT License
4.96k stars 513 forks source link

disallowQuotedKeysInObjects triggers on 64-bit integers which need to be quoted #2183

Closed kentonv closed 8 years ago

kentonv commented 8 years ago

Consider {"15831515641881813735": "foo"}. disallowQuotedKeysInObjects will flag an error here and insist that you write {15831515641881813735: "foo"} instead (and --fix will make this change). But, these are NOT equivalent because Javascript numbers lose precision after 52 bits, and this number uses a full 64 bits. You can see what happens on the Chrome dev console:

> {"15831515641881813735": "foo"}
Object {15831515641881813735: "foo"}
> {15831515641881813735: "foo"}
Object {15831515641881813000: "foo"}

Notice the last three digits have been rounded to zero!

Or to make it ever more obvious:

> {"1583151564188181373515831515641881813735": "foo"}
Object {1583151564188181373515831515641881813735: "foo"}
> {1583151564188181373515831515641881813735: "foo"}
Object {1.5831515641881813e+39: "foo"}

disallowQuotedKeysInObjects should ignore numeric strings that can't be represented in a double-precision float.

markelog commented 8 years ago

At this point only major and CST related bugs will be fixed.