node/tools/eslint/lib/rules/no-reserved-keys.js
Roman Reiss d91e10b3bd tools: update eslint to 0.24.0
PR-URL: https://github.com/nodejs/io.js/pull/2072
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alex Kocharin <alex@kocharin.ru>
2015-06-29 19:02:17 +02:00

56 lines
1.6 KiB
JavaScript

/**
* @fileoverview Rule to disallow reserved words being used as keys
* @author Emil Bay
* @copyright 2014 Emil Bay. All rights reserved.
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function(context) {
var MESSAGE = "Reserved word '{{key}}' used as key.";
var reservedWords = [
"abstract",
"boolean", "break", "byte",
"case", "catch", "char", "class", "const", "continue",
"debugger", "default", "delete", "do", "double",
"else", "enum", "export", "extends",
"final", "finally", "float", "for", "function",
"goto",
"if", "implements", "import", "in", "instanceof", "int", "interface",
"long",
"native", "new",
"package", "private", "protected", "public",
"return",
"short", "static", "super", "switch", "synchronized",
"this", "throw", "throws", "transient", "try", "typeof",
"var", "void", "volatile",
"while", "with"
];
return {
"ObjectExpression": function(node) {
node.properties.forEach(function(property) {
if (property.key.type === "Identifier") {
var keyName = property.key.name;
if (reservedWords.indexOf("" + keyName) !== -1) {
context.report(node, MESSAGE, { key: keyName });
}
}
});
}
};
};
module.exports.schema = [];