source: imaps-frontend/node_modules/eslint/lib/rules/wrap-regex.js

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.8 KB
Line 
1/**
2 * @fileoverview Rule to flag when regex literals are not wrapped in parens
3 * @author Matt DuVall <http://www.mattduvall.com>
4 * @deprecated in ESLint v8.53.0
5 */
6
7"use strict";
8
9//------------------------------------------------------------------------------
10// Rule Definition
11//------------------------------------------------------------------------------
12
13/** @type {import('../shared/types').Rule} */
14module.exports = {
15 meta: {
16 deprecated: true,
17 replacedBy: [],
18 type: "layout",
19
20 docs: {
21 description: "Require parenthesis around regex literals",
22 recommended: false,
23 url: "https://eslint.org/docs/latest/rules/wrap-regex"
24 },
25
26 schema: [],
27 fixable: "code",
28
29 messages: {
30 requireParens: "Wrap the regexp literal in parens to disambiguate the slash."
31 }
32 },
33
34 create(context) {
35 const sourceCode = context.sourceCode;
36
37 return {
38
39 Literal(node) {
40 const token = sourceCode.getFirstToken(node),
41 nodeType = token.type;
42
43 if (nodeType === "RegularExpression") {
44 const beforeToken = sourceCode.getTokenBefore(node);
45 const afterToken = sourceCode.getTokenAfter(node);
46 const { parent } = node;
47
48 if (parent.type === "MemberExpression" && parent.object === node &&
49 !(beforeToken && beforeToken.value === "(" && afterToken && afterToken.value === ")")) {
50 context.report({
51 node,
52 messageId: "requireParens",
53 fix: fixer => fixer.replaceText(node, `(${sourceCode.getText(node)})`)
54 });
55 }
56 }
57 }
58 };
59
60 }
61};
Note: See TracBrowser for help on using the repository browser.