From 361ac4d895c15086fb4351d4dca1405b2fdc4bd5 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Thu, 10 Sep 2020 23:43:55 +0200 Subject: [PATCH] Fix: NonOctalDecimalIntegerLiteral is decimal integer (fixes #13588) (#13664) --- lib/rules/utils/ast-utils.js | 4 ++- tests/lib/rules/dot-location.js | 18 +++++++++++++ tests/lib/rules/dot-notation.js | 25 +++++++++++++++++++ tests/lib/rules/no-extra-parens.js | 8 ++++++ .../rules/no-whitespace-before-property.js | 16 ++++++++++++ tests/lib/rules/utils/ast-utils.js | 19 ++++++++++++++ 6 files changed, 89 insertions(+), 1 deletion(-) diff --git a/lib/rules/utils/ast-utils.js b/lib/rules/utils/ast-utils.js index 6a42ce3686f..fb8beb25211 100644 --- a/lib/rules/utils/ast-utils.js +++ b/lib/rules/utils/ast-utils.js @@ -37,7 +37,7 @@ const LINEBREAKS = new Set(["\r\n", "\r", "\n", "\u2028", "\u2029"]); // A set of node types that can contain a list of statements const STATEMENT_LIST_PARENTS = new Set(["Program", "BlockStatement", "SwitchCase"]); -const DECIMAL_INTEGER_PATTERN = /^(0|[1-9](?:_?\d)*)$/u; +const DECIMAL_INTEGER_PATTERN = /^(?:0|0[0-7]*[89]\d*|[1-9](?:_?\d)*)$/u; const OCTAL_ESCAPE_PATTERN = /^(?:[^\\]|\\[^0-7]|\\0(?![0-9]))*\\(?:[1-7]|0[0-9])/u; const LOGICAL_ASSIGNMENT_OPERATORS = new Set(["&&=", "||=", "??="]); @@ -1244,6 +1244,8 @@ module.exports = { * 50 // true * 5_000 // true * 1_234_56 // true + * 08 // true + * 0192 // true * 5. // false * .5 // false * 5.0 // false diff --git a/tests/lib/rules/dot-location.js b/tests/lib/rules/dot-location.js index 82e23acab9b..bd56e1fc797 100644 --- a/tests/lib/rules/dot-location.js +++ b/tests/lib/rules/dot-location.js @@ -231,6 +231,24 @@ ruleTester.run("dot-location", rule, { options: ["object"], errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, + { + code: "01\n.toExponential()", + output: "01.\ntoExponential()", + options: ["object"], + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] + }, + { + code: "08\n.toExponential()", + output: "08 .\ntoExponential()", + options: ["object"], + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] + }, + { + code: "0190\n.toExponential()", + output: "0190 .\ntoExponential()", + options: ["object"], + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] + }, { code: "5_000\n.toExponential()", output: "5_000 .\ntoExponential()", diff --git a/tests/lib/rules/dot-notation.js b/tests/lib/rules/dot-notation.js index 56ea1321d97..39f3a676b0b 100644 --- a/tests/lib/rules/dot-notation.js +++ b/tests/lib/rules/dot-notation.js @@ -229,6 +229,31 @@ ruleTester.run("dot-notation", rule, { output: "-5 .prop", errors: [{ messageId: "useDot", data: { key: q("prop") } }] }, + { + code: "01['prop']", + output: "01.prop", + errors: [{ messageId: "useDot", data: { key: q("prop") } }] + }, + { + code: "01234567['prop']", + output: "01234567.prop", + errors: [{ messageId: "useDot", data: { key: q("prop") } }] + }, + { + code: "08['prop']", + output: "08 .prop", + errors: [{ messageId: "useDot", data: { key: q("prop") } }] + }, + { + code: "090['prop']", + output: "090 .prop", + errors: [{ messageId: "useDot", data: { key: q("prop") } }] + }, + { + code: "018['prop']", + output: "018 .prop", + errors: [{ messageId: "useDot", data: { key: q("prop") } }] + }, { code: "5_000['prop']", output: "5_000 .prop", diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index 6a4ba87a9d9..befdcda5a1c 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -190,6 +190,11 @@ ruleTester.run("no-extra-parens", rule, { // special cases "(0).a", + "(123).a", + "(08).a", + "(09).a", + "(018).a", + "(012934).a", "(5_000).a", "(5_000_00).a", "(function(){ }())", @@ -777,11 +782,14 @@ ruleTester.run("no-extra-parens", rule, { invalid("(a).b", "a.b", "Identifier"), invalid("(0)[a]", "0[a]", "Literal"), invalid("(0.0).a", "0.0.a", "Literal"), + invalid("(123.4).a", "123.4.a", "Literal"), invalid("(0.0_0).a", "0.0_0.a", "Literal"), invalid("(0xBEEF).a", "0xBEEF.a", "Literal"), invalid("(0xBE_EF).a", "0xBE_EF.a", "Literal"), invalid("(1e6).a", "1e6.a", "Literal"), invalid("(0123).a", "0123.a", "Literal"), + invalid("(08.1).a", "08.1.a", "Literal"), + invalid("(09.).a", "09..a", "Literal"), invalid("a[(function() {})]", "a[function() {}]", "FunctionExpression"), invalid("new (function(){})", "new function(){}", "FunctionExpression"), invalid("new (\nfunction(){}\n)", "new \nfunction(){}\n", "FunctionExpression", 1), diff --git a/tests/lib/rules/no-whitespace-before-property.js b/tests/lib/rules/no-whitespace-before-property.js index 5dceeeadf9e..485588dc9d5 100644 --- a/tests/lib/rules/no-whitespace-before-property.js +++ b/tests/lib/rules/no-whitespace-before-property.js @@ -842,6 +842,22 @@ ruleTester.run("no-whitespace-before-property", rule, { data: { propName: "toExponential" } }] }, + { + code: "08 .toExponential()", + output: null, // Not fixed + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] + }, + { + code: "0192 .toExponential()", + output: null, // Not fixed + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] + }, { code: "5_000 .toExponential()", output: null, // Not fixed, diff --git a/tests/lib/rules/utils/ast-utils.js b/tests/lib/rules/utils/ast-utils.js index a419e672177..8d60a11d70c 100644 --- a/tests/lib/rules/utils/ast-utils.js +++ b/tests/lib/rules/utils/ast-utils.js @@ -739,6 +739,8 @@ describe("ast-utils", () => { const expectedResults = { 0: true, 5: true, + 8: true, + 9: true, 50: true, 123: true, "1_0": true, @@ -752,6 +754,20 @@ describe("ast-utils", () => { "1_2_3_4": true, "11_22_33_44": true, "1_23_4_56_7_89": true, + "08": true, + "09": true, + "008": true, + "0192": true, + "0180": true, + "090": true, + "088": true, + "099": true, + "089": true, + "0098": true, + "01892": true, + "08192": true, + "01829": true, + "018290": true, "0.": false, "5.": false, ".0": false, @@ -765,6 +781,9 @@ describe("ast-utils", () => { ".0_1": false, ".12_34": false, "05": false, + "0123": false, + "076543210": false, + "08.": false, "0x5": false, "0b11_01": false, "0o0_1": false,