--- source: crates/rome_formatter_test/src/snapshot_builder.rs info: test_file: js/quote-props/objects.js --- # Input ```js const a = { a: "a" }; const b = { 'b': "b" }; const b2 = { // Escapes should stay as escapes and not be unquoted. '\u0062': "b", '\u0031': "1" }; const c = { c1: "c1", 'c2': "c2" }; const d = { d1: "d1", 'd-2': "d2" }; // None of these should become quoted, regardless of the quoteProps value. const e = { NaN: null, 1: null, 1.5: null, .1: null, 1.: null, 1.0: null, 999999999999999999999: null, 0.99999999999999999: null, 1E2: null, 1e+3: null, 1e+100: null, 0b10: null, 0o10: null, 0xf: null, 2n: null, } const f = { // These should be unquoted for quoteProps=as-needed. "NaN": null, "1": null, "1.5": null, // These should never be unquoted. `1e+100` technically could (it’s the only // one where `String(Number(key)) === key`), but we came to the conclusion // that it is unexpected. ".1": null, "1.": null, "1.0": null, "999999999999999999999": null, "0.99999999999999999": null, "1E2": null, "1e+3": null, "1e+100": null, "0b10": null, "0o10": null, "0xf": null, "2n": null, } Object.entries({ // To force quotes for quoteProps=consistent. 'a-': 'a-', // These can be quoted: NaN: 'NaN', 1: '1', 1.5: '1.5', // Prettier will normalize these to `0.1` and `1` – then they can be quoted. .1: '.1', 1.: '1.', // These should never be quoted. The _actual_ keys are shown as comments. // Copy-paste this into the console to verify. If we were to convert these // numbers into decimal (which completely valid), “information/intent” is // lost. Either way, writing code like this is super confusing. 1.0: '1.0', // 1 999999999999999999999: '999999999999999999999', // 1e+21 0.99999999999999999: '0.99999999999999999', // 1 1E2: '1E2', // 100 1e+3: '1e+3', // 1000 1e+100: '1e+100', // 1e+100 – this one is identical, but would be inconsistent to quote. 0b10: '0b10', // 2 0o10: '0o10', // 8 0xf: '0xf', // 15 2n: '2n', // 2 0xan: '0xan', // 10 }) // Negative numbers cannot be unquoted. !{ "-1": null, "-1.5": null, } ``` # Prettier differences ```diff --- Prettier +++ Rome @@ -27,14 +27,14 @@ NaN: null, 1: null, 1.5: null, - 0.1: null, - 1: null, + .1: null, + 1.: null, 1.0: null, 999999999999999999999: null, 0.99999999999999999: null, - 1e2: null, - 1e3: null, - 1e100: null, + 1E2: null, + 1e+3: null, + 1e+100: null, 0b10: null, 0o10: null, 0xf: null, @@ -45,14 +45,14 @@ // These should be unquoted for quoteProps=as-needed. NaN: null, 1: null, - 1.5: null, + "1.5": null, // These should never be unquoted. `1e+100` technically could (it’s the only // one where `String(Number(key)) === key`), but we came to the conclusion // that it is unexpected. ".1": null, "1.": null, "1.0": null, - "999999999999999999999": null, + 999999999999999999999: null, "0.99999999999999999": null, "1E2": null, "1e+3": null, @@ -71,8 +71,8 @@ 1: "1", 1.5: "1.5", // Prettier will normalize these to `0.1` and `1` – then they can be quoted. - 0.1: ".1", - 1: "1.", + .1: ".1", + 1.: "1.", // These should never be quoted. The _actual_ keys are shown as comments. // Copy-paste this into the console to verify. If we were to convert these // numbers into decimal (which completely valid), “information/intent” is @@ -80,9 +80,9 @@ 1.0: "1.0", // 1 999999999999999999999: "999999999999999999999", // 1e+21 0.99999999999999999: "0.99999999999999999", // 1 - 1e2: "1E2", // 100 - 1e3: "1e+3", // 1000 - 1e100: "1e+100", // 1e+100 – this one is identical, but would be inconsistent to quote. + 1E2: "1E2", // 100 + 1e+3: "1e+3", // 1000 + 1e+100: "1e+100", // 1e+100 – this one is identical, but would be inconsistent to quote. 0b10: "0b10", // 2 0o10: "0o10", // 8 0xf: "0xf", // 15 ``` # Output ```js const a = { a: "a", }; const b = { b: "b", }; const b2 = { // Escapes should stay as escapes and not be unquoted. "\u0062": "b", "\u0031": "1", }; const c = { c1: "c1", c2: "c2", }; const d = { d1: "d1", "d-2": "d2", }; // None of these should become quoted, regardless of the quoteProps value. const e = { NaN: null, 1: null, 1.5: null, .1: null, 1.: null, 1.0: null, 999999999999999999999: null, 0.99999999999999999: null, 1E2: null, 1e+3: null, 1e+100: null, 0b10: null, 0o10: null, 0xf: null, 2n: null, }; const f = { // These should be unquoted for quoteProps=as-needed. NaN: null, 1: null, "1.5": null, // These should never be unquoted. `1e+100` technically could (it’s the only // one where `String(Number(key)) === key`), but we came to the conclusion // that it is unexpected. ".1": null, "1.": null, "1.0": null, 999999999999999999999: null, "0.99999999999999999": null, "1E2": null, "1e+3": null, "1e+100": null, "0b10": null, "0o10": null, "0xf": null, "2n": null, }; Object.entries({ // To force quotes for quoteProps=consistent. "a-": "a-", // These can be quoted: NaN: "NaN", 1: "1", 1.5: "1.5", // Prettier will normalize these to `0.1` and `1` – then they can be quoted. .1: ".1", 1.: "1.", // These should never be quoted. The _actual_ keys are shown as comments. // Copy-paste this into the console to verify. If we were to convert these // numbers into decimal (which completely valid), “information/intent” is // lost. Either way, writing code like this is super confusing. 1.0: "1.0", // 1 999999999999999999999: "999999999999999999999", // 1e+21 0.99999999999999999: "0.99999999999999999", // 1 1E2: "1E2", // 100 1e+3: "1e+3", // 1000 1e+100: "1e+100", // 1e+100 – this one is identical, but would be inconsistent to quote. 0b10: "0b10", // 2 0o10: "0o10", // 8 0xf: "0xf", // 15 2n: "2n", // 2 0xan: "0xan", // 10 }); // Negative numbers cannot be unquoted. !{ "-1": null, "-1.5": null, }; ``` # Lines exceeding max width of 80 characters ``` 85: 1e+100: "1e+100", // 1e+100 – this one is identical, but would be inconsistent to quote. ```