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