1 | /**
|
2 | * @fileoverview Rule to flag octal escape sequences in string literals.
|
3 | * @author Ian Christian Myers
|
4 | */
|
5 |
|
6 | ;
|
7 |
|
8 | //------------------------------------------------------------------------------
|
9 | // Rule Definition
|
10 | //------------------------------------------------------------------------------
|
11 |
|
12 | module.exports = function(context) {
|
13 |
|
14 | return {
|
15 |
|
16 | "Literal": function(node) {
|
17 | if (typeof node.value !== "string") {
|
18 | return;
|
19 | }
|
20 |
|
21 | var match = node.raw.match(/^([^\\]|\\[^0-7])*\\([0-3][0-7]{1,2}|[4-7][0-7]|[0-7])/),
|
22 | octalDigit;
|
23 |
|
24 | if (match) {
|
25 | octalDigit = match[2];
|
26 |
|
27 | // \0 is actually not considered an octal
|
28 | if (match[2] !== "0" || typeof match[3] !== "undefined") {
|
29 | context.report(node, "Don't use octal: '\\{{octalDigit}}'. Use '\\u....' instead.",
|
30 | { octalDigit: octalDigit });
|
31 | }
|
32 | }
|
33 | }
|
34 |
|
35 | };
|
36 |
|
37 | };
|
38 |
|
39 | module.exports.schema = [];
|