Skip to content

Commit e936e8c

Browse files
requireDictionaryWords: Add identifier options
1 parent 316529c commit e936e8c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/rules/require-dictionary-words.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ module.exports.prototype = {
208208

209209
var wordDictionaries = ['english'];
210210
var allowedWords;
211+
var allowedIdentifierWords;
211212
var allowedPropertyWords;
212213
var allowedNames;
214+
var allowedIdentifierNames;
213215
var allowedPropertyNames;
214216
var excludedWords;
215217

@@ -228,8 +230,10 @@ module.exports.prototype = {
228230
if (wasObject) {
229231
wordDictionaries = arrayOption('dictionaries') || wordDictionaries;
230232
allowedWords = arrayOption('allowWords');
233+
allowedIdentifierWords = arrayOption('allowWordsInIdentifiers');
231234
allowedPropertyWords = arrayOption('allowWordsInProperties');
232235
allowedNames = arrayOption('allowNames');
236+
allowedIdentifierNames = arrayOption('allowNamesAsIdentifiers');
233237
allowedPropertyNames = arrayOption('allowNamesAsProperties');
234238
excludedWords = arrayOption('excludeWords');
235239
}
@@ -257,6 +261,11 @@ module.exports.prototype = {
257261
this._wordDictionaries.push(allowedWords);
258262
}
259263

264+
this._identifierWordDictionaries = this._wordDictionaries.slice();
265+
if (allowedIdentifierWords) {
266+
this._identifierWordDictionaries.push(allowedIdentifierWords);
267+
}
268+
260269
this._propertyWordDictionaries = this._wordDictionaries.slice();
261270
if (allowedPropertyWords) {
262271
this._propertyWordDictionaries.push(allowedPropertyWords);
@@ -267,6 +276,11 @@ module.exports.prototype = {
267276
this._nameDictionaries.push(allowedNames);
268277
}
269278

279+
this._identifierNameDictionaries = this._nameDictionaries.slice();
280+
if (allowedIdentifierNames) {
281+
this._identifierNameDictionaries.push(allowedIdentifierNames);
282+
}
283+
270284
this._propertyNameDictionaries = this._nameDictionaries.slice();
271285
if (allowedPropertyNames) {
272286
this._propertyNameDictionaries.push(allowedPropertyNames);
@@ -294,10 +308,10 @@ module.exports.prototype = {
294308
}
295309
}
296310

297-
function checkIdentifierOrProperty(name, start) {
311+
function checkIdentifier(name, start) {
298312
check(
299-
_this._wordDictionaries,
300-
_this._nameDictionaries,
313+
_this._identifierWordDictionaries,
314+
_this._identifierNameDictionaries,
301315
name,
302316
start
303317
);
@@ -316,7 +330,7 @@ module.exports.prototype = {
316330
if (!isSignificantNode(node)) {
317331
return;
318332
}
319-
checkIdentifierOrProperty(node.name, node.loc.start);
333+
checkIdentifier(node.name, node.loc.start);
320334
});
321335

322336
file.iterateNodesByType('MemberExpression', function(node) {

0 commit comments

Comments
 (0)