Skip to content

Commit

Permalink
fix: Make sure flaggedWords are always checked. (#1935)
Browse files Browse the repository at this point in the history
* Make sure flaggedWords are always checked.
  Fix: #1895
* ignore deliberate misspelling
* Update English dictionary
  • Loading branch information
Jason3S committed Nov 1, 2021
1 parent f2e9380 commit dfbfddd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
2 changes: 2 additions & 0 deletions docs/configuration/index.md
Expand Up @@ -30,6 +30,8 @@ Or you can specify a path to a config file with the `--config <path>` argument o

#### Example `cspell.json` file

<!--- cspell:ignore hte -->

```javascript
// cSpell Settings
{
Expand Down
6 changes: 3 additions & 3 deletions packages/cspell-bundled-dicts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cspell-bundled-dicts/package.json
Expand Up @@ -55,7 +55,7 @@
"@cspell/dict-dotnet": "^1.0.32",
"@cspell/dict-elixir": "^1.0.26",
"@cspell/dict-en-gb": "^1.1.33",
"@cspell/dict-en_us": "^2.1.2",
"@cspell/dict-en_us": "^2.1.3",
"@cspell/dict-filetypes": "^2.0.1",
"@cspell/dict-fonts": "^1.0.14",
"@cspell/dict-fullstack": "^2.0.4",
Expand Down
Expand Up @@ -54,7 +54,7 @@ describe('Validate getDictionary', () => {
expect(dict.has(word, opts)).toBe(expected);
});

// cspell:ignore zeromq
// cspell:ignore zeromq hte
test.each`
word | expected
${'zero'} | ${{ found: false, forbidden: false, noSuggest: false }}
Expand Down
18 changes: 11 additions & 7 deletions packages/cspell-lib/src/textValidator.test.ts
Expand Up @@ -209,14 +209,18 @@ describe('Validate textValidator functions', () => {
});

test.each`
text | ignoreWords | expected
${'red'} | ${[]} | ${[]}
${'color'} | ${[]} | ${[ov({ text: 'color', isFound: false })]}
${'colour'} | ${[]} | ${[ov({ text: 'colour', isFlagged: true })]}
${'colour'} | ${['colour']} | ${[]}
`('Validate forbidden words', ({ text, ignoreWords, expected }) => {
text | ignoreWords | flagWords | expected
${'red'} | ${[]} | ${undefined} | ${[]}
${'color'} | ${[]} | ${undefined} | ${[ov({ text: 'color', isFound: false })]}
${'colour'} | ${[]} | ${undefined} | ${[ov({ text: 'colour', isFlagged: true })]}
${'colour'} | ${['colour']} | ${undefined} | ${[]}
${'The ant ate the antelope.'} | ${[]} | ${['fbd']} | ${[]}
${'The ant ate the antelope.'} | ${[]} | ${['ate']} | ${[ov({ text: 'ate', isFlagged: true })]}
${'theANT_ateThe_antelope.'} | ${[]} | ${['ate']} | ${[ov({ text: 'ate', isFlagged: true })]}
${'The ant ate the antelope.'} | ${[]} | ${['antelope']} | ${[ov({ text: 'antelope', isFlagged: true })]}
`('Validate forbidden words', ({ text, ignoreWords, expected, flagWords }) => {
const dict = getSpellingDictionaryCollectionSync({ ignoreWords });
const result = [...validateText(text, dict, { ignoreCase: false })];
const result = [...validateText(text, dict, { ignoreCase: false, flagWords })];
expect(result).toEqual(expected);
});
});
Expand Down
9 changes: 3 additions & 6 deletions packages/cspell-lib/src/textValidator.ts
Expand Up @@ -153,12 +153,9 @@ function lineValidator(dict: SpellingDictionary, options: ValidationOptions): Li

const codeWordResults = Text.extractWordsFromCodeTextOffset(vr)
.filter(filterAlreadyChecked)
.filter(rememberFilter((wo) => wo.text.length >= minWordLength))
.map((t) => ({ ...t, line: vr.line }))
.map((wo) => {
const vr: ValidationResult = wo;
return vr;
})
.map(checkFlagWords)
.filter(rememberFilter((wo) => wo.text.length >= minWordLength || !!wo.isFlagged))
.map((wo) => (wo.isFlagged ? wo : checkWord(wo, hasWordOptions)))
.filter(rememberFilter((wo) => wo.isFlagged || !wo.isFound))
.filter(rememberFilter((wo) => !RxPat.regExRepeatedChar.test(wo.text))) // Filter out any repeated characters like xxxxxxxxxx
Expand All @@ -180,9 +177,9 @@ function lineValidator(dict: SpellingDictionary, options: ValidationOptions): Li
function checkPossibleWords(possibleWord: TextOffset) {
const mismatches: ValidationResult[] = Text.extractWordsFromTextOffset(possibleWord)
.filter(filterAlreadyChecked)
.filter(rememberFilter((wo) => wo.text.length >= minWordLength))
.map((wo) => ({ ...wo, line: lineSegment }))
.map(checkFlagWords)
.filter(rememberFilter((wo) => wo.text.length >= minWordLength || !!wo.isFlagged))
.concatMap(checkFullWord)
.toArray();
if (mismatches.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/trace.test.ts
Expand Up @@ -25,7 +25,7 @@ describe('Verify trace', () => {
);
});

// cspell:ignore *error* *code*
// cspell:ignore *error* *code* hte
test.each`
word | languageId | locale | ignoreCase | allowCompoundWords | dictName | dictActive | found | forbidden | noSuggest | foundWord
${'apple'} | ${undefined} | ${undefined} | ${true} | ${undefined} | ${'en_us'} | ${true} | ${true} | ${false} | ${false} | ${'apple'}
Expand Down
1 change: 1 addition & 0 deletions packages/cspell-lib/src/validator.test.ts
Expand Up @@ -239,6 +239,7 @@ const sampleWords = [
'worm',
];

// cspell:ignore hte
const flagWords = ['hte', 'flagged', 'ignored'];
// cspell:ignore behaviour
const rejectWords = ['!colour', '!behaviour', '!favour'];
Expand Down

0 comments on commit dfbfddd

Please sign in to comment.