UNPKG

1.01 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to check for ambiguous div operator in regexes
3 * @author Matt DuVall <http://www.mattduvall.com>
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
14 docs: {
15 description: "disallow division operators explicitly at the beginning of regular expressions",
16 category: "Best Practices",
17 recommended: false
18 },
19
20 schema: []
21 },
22
23 create(context) {
24 const sourceCode = context.getSourceCode();
25
26 return {
27
28 Literal(node) {
29 const token = sourceCode.getFirstToken(node);
30
31 if (token.type === "RegularExpression" && token.value[1] === "=") {
32 context.report(node, "A regular expression literal can be confused with '/='.");
33 }
34 }
35 };
36
37 }
38};