Skip to content

Commit

Permalink
fix: catch flagged words with - when ending with . (#6608)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Nov 27, 2024
1 parent 5765848 commit 101bf36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('lineValidatorFactory', () => {
word | expected
${'one'} | ${[]}
${'three etc.'} | ${[]}
${'flip-flop'} | ${[oc({ text: 'flip-flop', isFlagged: true })]}
${'one flip-flop.'} | ${[oc({ text: 'flip-flop', isFlagged: true })]}
${'one two three etc'} | ${[oc({ text: 'etc' })]}
${'three four five one'} | ${[oc({ text: 'five' })]}
${'lion'} | ${[oc({ text: 'lion', suggestionsEx: [oc({ word: 'tiger', isPreferred: true })] })]}
Expand All @@ -26,8 +28,8 @@ let dict: SpellingDictionary | undefined;

function getDict(): SpellingDictionary {
if (dict) return dict;
const words = 'one two three four etc. a.b.c'.split(/\s/g);
const suggestions = 'apple:pear lion:tiger'.split(/\s/g);
const words = 'one two three four etc. a.b.c !flip-flop'.split(' ');
const suggestions = 'apple:pear lion:tiger'.split(' ');
const d = createCollection(
[
createSpellingDictionary(words, 'words', 'tests'),
Expand Down
33 changes: 25 additions & 8 deletions packages/cspell-lib/src/lib/textValidation/lineValidatorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,29 @@ export function lineValidatorFactory(sDict: SpellingDictionary, options: Validat
});
}

function checkForFlaggedWord(possibleWord: TextOffsetRO): ValidationIssue | undefined {
if (isWordFlagged(possibleWord)) {
const vr: ValidationIssueRO = {
...possibleWord,
line: lineSegment.line,
isFlagged: true,
};
return vr;
}
if (possibleWord.text.endsWith('.')) {
const pw = { ...possibleWord, text: possibleWord.text.slice(0, -1) };
if (isWordFlagged(pw)) {
const vr: ValidationIssueRO = {
...pw,
line: lineSegment.line,
isFlagged: true,
};
return vr;
}
}
return undefined;
}

function checkPossibleWords(possibleWord: TextOffsetRO): ValidationIssue[] {
const known = setOfKnownIssues.get(possibleWord.text);
if (known) {
Expand All @@ -285,14 +308,8 @@ export function lineValidatorFactory(sDict: SpellingDictionary, options: Validat
}

function _checkPossibleWords(possibleWord: TextOffsetRO): ValidationIssue[] {
if (isWordFlagged(possibleWord)) {
const vr: ValidationIssueRO = {
...possibleWord,
line: lineSegment.line,
isFlagged: true,
};
return [vr];
}
const flagged = checkForFlaggedWord(possibleWord);
if (flagged) return [flagged];

const mismatches: ValidationIssue[] = [];
for (const wo of extractWordsFromTextOffset(possibleWord)) {
Expand Down

0 comments on commit 101bf36

Please sign in to comment.