Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make sure flaggedWords are always checked. #1935

Merged
merged 5 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/configuration/index.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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