UNPKG

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