Skip to content

Commit

Permalink
Fix: no-octal should report NonOctalDecimalIntegerLiteral (fixes #11794
Browse files Browse the repository at this point in the history
…) (#11805)

Examples: 08, 018, 08.1
  • Loading branch information
mdjermanovic authored and platinumazure committed Jun 8, 2019
1 parent e4ab053 commit 87451f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-octal.js
Expand Up @@ -28,7 +28,7 @@ module.exports = {
return {

Literal(node) {
if (typeof node.value === "number" && /^0[0-7]/u.test(node.raw)) {
if (typeof node.value === "number" && /^0[0-9]/u.test(node.raw)) {
context.report({ node, message: "Octal literals should not be used." });
}
}
Expand Down
10 changes: 9 additions & 1 deletion tests/lib/rules/no-octal.js
Expand Up @@ -30,6 +30,14 @@ ruleTester.run("no-octal", rule, {
invalid: [
{ code: "var a = 01234;", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "a = 1 + 01234;", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "00", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] }
{ code: "00", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "08", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "09.1", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "09e1", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "09.1e1", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "018", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "019.1", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "019e1", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] },
{ code: "019.1e1", errors: [{ message: "Octal literals should not be used.", type: "Literal" }] }
]
});

0 comments on commit 87451f4

Please sign in to comment.