1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.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 | url: "https://eslint.org/docs/rules/no-div-regex"
|
19 | },
|
20 |
|
21 | schema: [],
|
22 |
|
23 | messages: {
|
24 | unexpected: "A regular expression literal can be confused with '/='."
|
25 | }
|
26 | },
|
27 |
|
28 | create(context) {
|
29 | const sourceCode = context.getSourceCode();
|
30 |
|
31 | return {
|
32 |
|
33 | Literal(node) {
|
34 | const token = sourceCode.getFirstToken(node);
|
35 |
|
36 | if (token.type === "RegularExpression" && token.value[1] === "=") {
|
37 | context.report({ node, messageId: "unexpected" });
|
38 | }
|
39 | }
|
40 | };
|
41 |
|
42 | }
|
43 | };
|