node/tools/eslint/lib/rules/no-restricted-syntax.js
silverwind d9b8758f47 tools: update ESLint to 2.7.0
PR-URL: https://github.com/nodejs/node/pull/6132
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: thefourtheye <thechargingvolcano@gmail.com>
2016-04-20 16:24:21 -07:00

44 lines
1.1 KiB
JavaScript

/**
* @fileoverview Rule to flag use of certain node types
* @author Burak Yigit Kaya
* @copyright 2015 Burak Yigit Kaya. All rights reserved.
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
var nodeTypes = require("espree").Syntax;
module.exports = function(context) {
/**
* Generates a warning from the provided node, saying that node type is not allowed.
* @param {ASTNode} node The node to warn on
* @returns {void}
*/
function warn(node) {
context.report(node, "Using '{{type}}' is not allowed.", node);
}
return context.options.reduce(function(result, nodeType) {
result[nodeType] = warn;
return result;
}, {});
};
module.exports.schema = {
"type": "array",
"items": [
{
"enum": Object.keys(nodeTypes).map(function(k) {
return nodeTypes[k];
})
}
],
"uniqueItems": true,
"minItems": 0
};