Skip to content

Commit 316529c

Browse files
requireDictionaryWords: Add specifications for identifier options
1 parent e5980f5 commit 316529c

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

lib/rules/require-dictionary-words.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
* - `dictionaries`: (default `["english"]`) array of dictionary names including
1414
* `"english"`, `"american"`, `"british"` and `"canadian"`
1515
* - `allowWords`: additional words allowed anywhere
16-
* - `allowWordsInProperties`: additional words allowed only as properties
16+
* - `allowWordsInIdentifiers`: additional words allowed only in identifiers
17+
* - `allowWordsInProperties`: additional words allowed only in properties
1718
* - `allowNames`: names ignored by spellcheck
18-
* - `allowNamesAsProperties`: names ignored by spellcheck when used as properties
19+
* - `allowNamesAsIdentifiers`: whole names ignored by spellcheck when used as identifiers
20+
* - `allowNamesAsProperties`: whole names ignored by spellcheck when used as properties
1921
* - `excludeWords`: words to exclude from the dictionaries
2022
*
2123
* #### Example
@@ -27,7 +29,7 @@
2729
* "dictionaries": [ "english", "american" ],
2830
* "allowWords": [ "transclude" ],
2931
* "allowWordsInProperties": [ "chmod" ],
30-
* "allowNames": [ "$stateParams", "util" ],
32+
* "allowNamesAsIdentifiers": [ "$stateParams", "util" ],
3133
* "allowNamesAsProperties": [ "src" ],
3234
* "excludeWords": [ "i" ]
3335
* }
@@ -85,14 +87,14 @@
8587
* var chmod = 0777;
8688
* ```
8789
*
88-
* ##### Valid for mode `"allowNames": [ "$stateParams", "util" ]`
90+
* ##### Valid for mode `"allowNamesAsIdentifiers": [ "$stateParams", "util" ]`
8991
*
9092
* ```js
9193
* var util = require('util');
9294
* function Controller($stateParams) {}
9395
* ```
9496
*
95-
* ##### Invalid for mode `"allowNames": [ "$stateParams", "util" ]`
97+
* ##### Invalid for mode `"allowNamesAsIdentifiers": [ "$stateParams", "util" ]`
9698
*
9799
* ```js
98100
* var stringUtil = {};

test/specs/rules/require-dictionary-words.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ describe('rules/require-dictionary-words', function() {
120120
});
121121
});
122122

123+
describe('allowWordsInIdentifiers', function() {
124+
beforeEach(function() {
125+
checker.configure({
126+
requireDictionaryWords: {
127+
allowWordsInIdentifiers: ['asdf', 'jkl']
128+
}
129+
});
130+
});
131+
132+
it('should report non-words in properties', function() {
133+
assert(checker.checkString('object.jkl = 1;').getErrorCount() === 1);
134+
assert(checker.checkString('object.jklJkl = 1;').getErrorCount() === 2);
135+
});
136+
137+
it('should not report allowed words in identifiers', function() {
138+
assert(checker.checkString('asdf = 1;').isEmpty());
139+
assert(checker.checkString('asdfAsdf = 1;').isEmpty());
140+
});
141+
});
142+
123143
describe('allowWordsInProperties', function() {
124144
beforeEach(function() {
125145
checker.configure({
@@ -140,6 +160,26 @@ describe('rules/require-dictionary-words', function() {
140160
});
141161
});
142162

163+
describe('allowNamesAsIdentifiers', function() {
164+
beforeEach(function() {
165+
checker.configure({
166+
requireDictionaryWords: {
167+
allowNamesAsIdentifiers: ['asdf', 'jkl']
168+
}
169+
});
170+
});
171+
172+
it('should report non-names and properties', function() {
173+
assert(checker.checkString('asdfAsdf = 1;').getErrorCount() === 2);
174+
assert(checker.checkString('object.jkl = 1;').getErrorCount() === 1);
175+
assert(checker.checkString('object.jklJkl = 1;').getErrorCount() === 2);
176+
});
177+
178+
it('should not report allowed names as identifiers', function() {
179+
assert(checker.checkString('asdf = 1;').isEmpty());
180+
});
181+
});
182+
143183
describe('allowNamesAsProperties', function() {
144184
beforeEach(function() {
145185
checker.configure({

0 commit comments

Comments
 (0)