41aa9fa390a88d019f20fc1323359ded051930ee
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / rules / no-restricted-syntax.js
1 /**
2  * @fileoverview Rule to flag use of certain node types
3  * @author Burak Yigit Kaya
4  */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Rule Definition
9 //------------------------------------------------------------------------------
10
11 module.exports = {
12     meta: {
13         type: "suggestion",
14
15         docs: {
16             description: "disallow specified syntax",
17             category: "Stylistic Issues",
18             recommended: false,
19             url: "https://eslint.org/docs/rules/no-restricted-syntax"
20         },
21
22         schema: {
23             type: "array",
24             items: {
25                 oneOf: [
26                     {
27                         type: "string"
28                     },
29                     {
30                         type: "object",
31                         properties: {
32                             selector: { type: "string" },
33                             message: { type: "string" }
34                         },
35                         required: ["selector"],
36                         additionalProperties: false
37                     }
38                 ]
39             },
40             uniqueItems: true,
41             minItems: 0
42         }
43     },
44
45     create(context) {
46         return context.options.reduce((result, selectorOrObject) => {
47             const isStringFormat = (typeof selectorOrObject === "string");
48             const hasCustomMessage = !isStringFormat && Boolean(selectorOrObject.message);
49
50             const selector = isStringFormat ? selectorOrObject : selectorOrObject.selector;
51             const message = hasCustomMessage ? selectorOrObject.message : "Using '{{selector}}' is not allowed.";
52
53             return Object.assign(result, {
54                 [selector](node) {
55                     context.report({
56                         node,
57                         message,
58                         data: hasCustomMessage ? {} : { selector }
59                     });
60                 }
61             });
62         }, {});
63
64     }
65 };