1 | /**
|
2 | * @fileoverview Rule to flag use of certain node types
|
3 | * @author Burak Yigit Kaya
|
4 | */
|
5 | ;
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Rule Definition
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | const nodeTypes = require("espree").Syntax;
|
12 |
|
13 | module.exports = {
|
14 | meta: {
|
15 | docs: {
|
16 | description: "disallow specified syntax",
|
17 | category: "Stylistic Issues",
|
18 | recommended: false
|
19 | },
|
20 |
|
21 | schema: {
|
22 | type: "array",
|
23 | items: [
|
24 | {
|
25 | enum: Object.keys(nodeTypes).map(function(k) {
|
26 | return nodeTypes[k];
|
27 | })
|
28 | }
|
29 | ],
|
30 | uniqueItems: true,
|
31 | minItems: 0
|
32 | }
|
33 | },
|
34 |
|
35 | create(context) {
|
36 |
|
37 | /**
|
38 | * Generates a warning from the provided node, saying that node type is not allowed.
|
39 | * @param {ASTNode} node The node to warn on
|
40 | * @returns {void}
|
41 | */
|
42 | function warn(node) {
|
43 | context.report(node, "Using '{{type}}' is not allowed.", node);
|
44 | }
|
45 |
|
46 | return context.options.reduce(function(result, nodeType) {
|
47 | result[nodeType] = warn;
|
48 |
|
49 | return result;
|
50 | }, {});
|
51 |
|
52 | }
|
53 | };
|