source: imaps-frontend/node_modules/eslint/lib/rules/no-restricted-syntax.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[d565449]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/** @type {import('../shared/types').Rule} */
12module.exports = {
13 meta: {
14 type: "suggestion",
15
16 docs: {
17 description: "Disallow specified syntax",
18 recommended: false,
19 url: "https://eslint.org/docs/latest/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 messages: {
45 // eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
46 restrictedSyntax: "{{message}}"
47 }
48 },
49
50 create(context) {
51 return context.options.reduce((result, selectorOrObject) => {
52 const isStringFormat = (typeof selectorOrObject === "string");
53 const hasCustomMessage = !isStringFormat && Boolean(selectorOrObject.message);
54
55 const selector = isStringFormat ? selectorOrObject : selectorOrObject.selector;
56 const message = hasCustomMessage ? selectorOrObject.message : `Using '${selector}' is not allowed.`;
57
58 return Object.assign(result, {
59 [selector](node) {
60 context.report({
61 node,
62 messageId: "restrictedSyntax",
63 data: { message }
64 });
65 }
66 });
67 }, {});
68
69 }
70};
Note: See TracBrowser for help on using the repository browser.