2 * @fileoverview Rule to warn about using dot notation instead of square bracket notation when possible.
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 var validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
74 module.exports = function(context) {
75 var options = context.options[0] || {};
76 var allowKeywords = options.allowKeywords === void 0 || !!options.allowKeywords;
79 if (options.allowPattern) {
80 allowPattern = new RegExp(options.allowPattern);
84 "MemberExpression": function(node) {
87 node.property.type === "Literal" &&
88 validIdentifier.test(node.property.value) &&
89 (allowKeywords || keywords.indexOf("" + node.property.value) === -1)
91 if (!(allowPattern && allowPattern.test(node.property.value))) {
92 context.report(node, "[" + JSON.stringify(node.property.value) + "] is better written in dot notation.");
98 keywords.indexOf("" + node.property.name) !== -1
100 context.report(node, "." + node.property.name + " is a syntax error.");