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