Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Clone in Desktop Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (61 sloc) 1.67 KB
/**
* Disallows a specified set of identifier names.
*
* Type: `Array`
*
* Values: Array of strings, which should be disallowed as identifier names
*
* #### Example
*
* ```js
* "disallowIdentifierNames": ['temp', 'foo']
* ```
*
* ##### Valid
*
* ```js
* var good = 1;
* object['fine'] = 2;
* object.fine = 3;
* ```
*
* ##### Invalid
*
* ```js
* var temp = 1;
* object['foo'] = 2;
* object.foo = 3;
* ```
*/
var assert = require('assert');
module.exports = function() {};
module.exports.prototype = {
configure: function(identifiers) {
assert(
Array.isArray(identifiers),
'disallowIdentifierNames option requires an array'
);
this._identifierIndex = {};
for (var i = 0, l = identifiers.length; i < l; i++) {
this._identifierIndex[identifiers[i]] = true;
}
},
getOptionName: function() {
return 'disallowIdentifierNames';
},
check: function(file, errors) {
var disallowedIdentifiers = this._identifierIndex;
file.iterateNodesByType('Identifier', function(node) {
if (Object.prototype.hasOwnProperty.call(disallowedIdentifiers, node.name)) {
errors.add('Illegal Identifier name: ' + node.name, node.loc.start);
}
});
file.iterateNodesByType('MemberExpression', function(node) {
if (node.property.type === 'Literal') {
if (Object.prototype.hasOwnProperty.call(disallowedIdentifiers, node.property.value)) {
errors.add('Illegal Identifier name: ' + node.property.value, node.property.loc.start);
}
}
});
}
};
Jump to Line
Something went wrong with that request. Please try again.