]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-div-regex.js
dd1c5782a58940bb449bc50fff9020033edd3f0c
[pve-eslint.git] / eslint / lib / rules / no-div-regex.js
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
12 /** @type {import('../shared/types').Rule} */
13 module.exports = {
14 meta: {
15 type: "suggestion",
16
17 docs: {
18 description: "Disallow division operators explicitly at the beginning of regular expressions",
19 recommended: false,
20 url: "https://eslint.org/docs/rules/no-div-regex"
21 },
22
23 fixable: "code",
24
25 schema: [],
26
27 messages: {
28 unexpected: "A regular expression literal can be confused with '/='."
29 }
30 },
31
32 create(context) {
33 const sourceCode = context.getSourceCode();
34
35 return {
36
37 Literal(node) {
38 const token = sourceCode.getFirstToken(node);
39
40 if (token.type === "RegularExpression" && token.value[1] === "=") {
41 context.report({
42 node,
43 messageId: "unexpected",
44 fix(fixer) {
45 return fixer.replaceTextRange([token.range[0] + 1, token.range[0] + 2], "[=]");
46 }
47 });
48 }
49 }
50 };
51
52 }
53 };