UNPKG

886 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag when initializing octal literal
3 * @author Ilya Volodin
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
14 type: "suggestion",
15
16 docs: {
17 description: "disallow octal literals",
18 category: "Best Practices",
19 recommended: true,
20 url: "https://eslint.org/docs/rules/no-octal"
21 },
22
23 schema: []
24 },
25
26 create(context) {
27
28 return {
29
30 Literal(node) {
31 if (typeof node.value === "number" && /^0[0-9]/u.test(node.raw)) {
32 context.report({ node, message: "Octal literals should not be used." });
33 }
34 }
35 };
36
37 }
38};