main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
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 equal signs explicitly at the beginning of regular expressions",
|
---|
19 | recommended: false,
|
---|
20 | url: "https://eslint.org/docs/latest/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.sourceCode;
|
---|
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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.