Skip to content

Commit

Permalink
requireDictionaryWords: Add specifications for identifier options
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonrayhamilton committed Apr 4, 2015
1 parent e5980f5 commit 316529c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/rules/require-dictionary-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* - `dictionaries`: (default `["english"]`) array of dictionary names including
* `"english"`, `"american"`, `"british"` and `"canadian"`
* - `allowWords`: additional words allowed anywhere
* - `allowWordsInProperties`: additional words allowed only as properties
* - `allowWordsInIdentifiers`: additional words allowed only in identifiers
* - `allowWordsInProperties`: additional words allowed only in properties
* - `allowNames`: names ignored by spellcheck
* - `allowNamesAsProperties`: names ignored by spellcheck when used as properties
* - `allowNamesAsIdentifiers`: whole names ignored by spellcheck when used as identifiers
* - `allowNamesAsProperties`: whole names ignored by spellcheck when used as properties
* - `excludeWords`: words to exclude from the dictionaries
*
* #### Example
Expand All @@ -27,7 +29,7 @@
* "dictionaries": [ "english", "american" ],
* "allowWords": [ "transclude" ],
* "allowWordsInProperties": [ "chmod" ],
* "allowNames": [ "$stateParams", "util" ],
* "allowNamesAsIdentifiers": [ "$stateParams", "util" ],
* "allowNamesAsProperties": [ "src" ],
* "excludeWords": [ "i" ]
* }
Expand Down Expand Up @@ -85,14 +87,14 @@
* var chmod = 0777;
* ```
*
* ##### Valid for mode `"allowNames": [ "$stateParams", "util" ]`
* ##### Valid for mode `"allowNamesAsIdentifiers": [ "$stateParams", "util" ]`
*
* ```js
* var util = require('util');
* function Controller($stateParams) {}
* ```
*
* ##### Invalid for mode `"allowNames": [ "$stateParams", "util" ]`
* ##### Invalid for mode `"allowNamesAsIdentifiers": [ "$stateParams", "util" ]`
*
* ```js
* var stringUtil = {};
Expand Down
40 changes: 40 additions & 0 deletions test/specs/rules/require-dictionary-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ describe('rules/require-dictionary-words', function() {
});
});

describe('allowWordsInIdentifiers', function() {
beforeEach(function() {
checker.configure({
requireDictionaryWords: {
allowWordsInIdentifiers: ['asdf', 'jkl']
}
});
});

it('should report non-words in properties', function() {
assert(checker.checkString('object.jkl = 1;').getErrorCount() === 1);
assert(checker.checkString('object.jklJkl = 1;').getErrorCount() === 2);
});

it('should not report allowed words in identifiers', function() {
assert(checker.checkString('asdf = 1;').isEmpty());
assert(checker.checkString('asdfAsdf = 1;').isEmpty());
});
});

describe('allowWordsInProperties', function() {
beforeEach(function() {
checker.configure({
Expand All @@ -140,6 +160,26 @@ describe('rules/require-dictionary-words', function() {
});
});

describe('allowNamesAsIdentifiers', function() {
beforeEach(function() {
checker.configure({
requireDictionaryWords: {
allowNamesAsIdentifiers: ['asdf', 'jkl']
}
});
});

it('should report non-names and properties', function() {
assert(checker.checkString('asdfAsdf = 1;').getErrorCount() === 2);
assert(checker.checkString('object.jkl = 1;').getErrorCount() === 1);
assert(checker.checkString('object.jklJkl = 1;').getErrorCount() === 2);
});

it('should not report allowed names as identifiers', function() {
assert(checker.checkString('asdf = 1;').isEmpty());
});
});

describe('allowNamesAsProperties', function() {
beforeEach(function() {
checker.configure({
Expand Down

0 comments on commit 316529c

Please sign in to comment.