1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/**
* @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 = [];
|