Skip to content

Commit 8c947d3

Browse files
requireDictionaryWords: Use prefixed dictionary names
1 parent de313d3 commit 8c947d3

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To use, add these lines to your `.jscsrc` configuration file:
3333
{
3434
"plugins": [ "jscs-spellcheck" ],
3535
"requireDictionaryWords": {
36-
"dictionaries": [ "english", "american" ]
36+
"dictionaries": [ "english", "english/american" ]
3737
}
3838
}
3939
```
@@ -54,7 +54,7 @@ Values:
5454
- `true`: use the `"english"` dictionary
5555
- `Object`:
5656
- `dictionaries`: (default `["english"]`) array of dictionary names including
57-
`"english"`, `"american"`, `"british"` and `"canadian"`
57+
`"english"`, `"english/american"`, `"english/british"` and `"english/canadian"`
5858
- `allowWords`: additional words allowed anywhere
5959
- `allowWordsInIdentifiers`: additional words allowed only in identifiers
6060
- `allowWordsInProperties`: additional words allowed only in properties
@@ -69,7 +69,7 @@ Values:
6969
"requireDictionaryWords": true
7070

7171
"requireDictionaryWords": {
72-
"dictionaries": [ "english", "american" ],
72+
"dictionaries": [ "english", "english/american" ],
7373
"allowWords": [ "transclude" ],
7474
"allowWordsInProperties": [ "chmod" ],
7575
"allowNamesAsIdentifiers": [ "$stateParams", "util" ],
@@ -96,13 +96,13 @@ obj.src = 3;
9696
fileDir = 4;
9797
```
9898

99-
##### Valid for mode `"dictionaries": [ "american" ]`, invalid for `"british"`
99+
##### Valid for mode `"dictionaries": [ "english/american" ]`, invalid for `"english/british"`
100100

101101
```js
102102
var color = 'papayawhip';
103103
```
104104

105-
##### Valid for mode `"dictionaries": [ "british" ]`, invalid for `"american"`
105+
##### Valid for mode `"dictionaries": [ "english/british" ]`, invalid for `"english/american"`
106106

107107
```js
108108
var colour = 'papayawhip';

lib/rules/require-dictionary-words.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* - `true`: use the `"english"` dictionary
1212
* - `Object`:
1313
* - `dictionaries`: (default `["english"]`) array of dictionary names including
14-
* `"english"`, `"american"`, `"british"` and `"canadian"`
14+
* `"english"`, `"english/american"`, `"english/british"` and `"english/canadian"`
1515
* - `allowWords`: additional words allowed anywhere
1616
* - `allowWordsInIdentifiers`: additional words allowed only in identifiers
1717
* - `allowWordsInProperties`: additional words allowed only in properties
@@ -26,7 +26,7 @@
2626
* "requireDictionaryWords": true
2727
*
2828
* "requireDictionaryWords": {
29-
* "dictionaries": [ "english", "american" ],
29+
* "dictionaries": [ "english", "english/american" ],
3030
* "allowWords": [ "transclude" ],
3131
* "allowWordsInProperties": [ "chmod" ],
3232
* "allowNamesAsIdentifiers": [ "$stateParams", "util" ],
@@ -53,13 +53,13 @@
5353
* fileDir = 4;
5454
* ```
5555
*
56-
* ##### Valid for mode `"dictionaries": [ "american" ]`, invalid for `"british"`
56+
* ##### Valid for mode `"dictionaries": [ "english/american" ]`, invalid for `"english/british"`
5757
*
5858
* ```js
5959
* var color = 'papayawhip';
6060
* ```
6161
*
62-
* ##### Valid for mode `"dictionaries": [ "british" ]`, invalid for `"american"`
62+
* ##### Valid for mode `"dictionaries": [ "english/british" ]`, invalid for `"english/american"`
6363
*
6464
* ```js
6565
* var colour = 'papayawhip';
@@ -149,13 +149,6 @@ var assert = require('assert');
149149
var assign = require('lodash.assign');
150150
var indexOf = require('lodash.indexof');
151151

152-
var wordlistMap = {
153-
english: 'wordlist-english',
154-
american: 'wordlist-english',
155-
british: 'wordlist-english',
156-
canadian: 'wordlist-english',
157-
};
158-
159152
// Breaks names like "fooBar" into ["foo", "bar"], etc.
160153
var reWords = (function() {
161154
var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]';
@@ -267,12 +260,12 @@ module.exports.prototype = {
267260
}
268261

269262
this._wordDictionaries = wordDictionaries.map(function(language) {
270-
var packageName = wordlistMap.hasOwnProperty(language) ?
271-
// Special case where one package holds many wordlists.
272-
wordlistMap[language] :
273-
// General case where a package is one-to-one with a
274-
// wordlist.
275-
'wordlist-' + language;
263+
// Languages such as "wordlist-english" contain both "english" and
264+
// "english/american" languages.
265+
var firstPartMatch = language.match(/(.*?)\//);
266+
var packageName = firstPartMatch === null ?
267+
'wordlist-' + language :
268+
'wordlist-' + firstPartMatch[1];
276269
var wordlist;
277270
try {
278271
wordlist = require(packageName);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"dependencies": {
4343
"lodash.assign": "~3.0.0",
4444
"lodash.indexof": "~3.0.0",
45-
"wordlist-english": "^1.0.0"
45+
"wordlist-english": "^1.1.0"
4646
},
4747
"devDependencies": {
4848
"coveralls": "~2.11.2",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe('rules/require-dictionary-words', function() {
235235
beforeEach(function() {
236236
checker.configure({
237237
requireDictionaryWords: {
238-
dictionaries: ['english', 'american']
238+
dictionaries: ['english', 'english/american']
239239
}
240240
});
241241
});

0 commit comments

Comments
 (0)