Skip to content

Commit

Permalink
Fix: NonOctalDecimalIntegerLiteral is decimal integer (fixes #13588) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Sep 10, 2020
1 parent f260716 commit 361ac4d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rules/utils/ast-utils.js
Expand Up @@ -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(["&&=", "||=", "??="]);
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/dot-location.js
Expand Up @@ -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()",
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/rules/dot-notation.js
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/no-extra-parens.js
Expand Up @@ -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(){ }())",
Expand Down Expand Up @@ -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),
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-whitespace-before-property.js
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/utils/ast-utils.js
Expand Up @@ -739,6 +739,8 @@ describe("ast-utils", () => {
const expectedResults = {
0: true,
5: true,
8: true,
9: true,
50: true,
123: true,
"1_0": true,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 361ac4d

Please sign in to comment.