cspell-lib 8.13.2 → 8.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/textValidation/lineValidatorFactory.js +41 -6
- package/dist/lib/util/text.d.ts +6 -1
- package/dist/lib/util/text.js +14 -2
- package/dist/lib/util/textApi.d.ts +2 -0
- package/dist/lib/util/textApi.js +2 -0
- package/dist/lib/util/textRegex.d.ts +2 -1
- package/dist/lib/util/textRegex.js +3 -2
- package/dist/lib/util/wordSplitter.js +2 -2
- package/package.json +16 -16
package/dist/lib/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type { TraceOptions, TraceResult, TraceWordResult } from './trace.js';
|
|
|
25
25
|
export { traceWords, traceWordsAsync } from './trace.js';
|
|
26
26
|
export { getLogger, Logger, setLogger } from './util/logger.js';
|
|
27
27
|
export { resolveFile } from './util/resolveFile.js';
|
|
28
|
-
export * as Text from './util/
|
|
28
|
+
export * as Text from './util/textApi.js';
|
|
29
29
|
export { checkText, checkTextDocument, CheckTextInfo, IncludeExcludeFlag, IncludeExcludeOptions, TextInfoItem, validateText, ValidationIssue, } from './validator.js';
|
|
30
30
|
export * from '@cspell/cspell-types';
|
|
31
31
|
export { asyncIterableToArray, readFileText as readFile, readFileTextSync as readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from 'cspell-io';
|
package/dist/lib/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export { DocumentValidator, shouldCheckDocument } from './textValidation/index.j
|
|
|
18
18
|
export { traceWords, traceWordsAsync } from './trace.js';
|
|
19
19
|
export { getLogger, setLogger } from './util/logger.js';
|
|
20
20
|
export { resolveFile } from './util/resolveFile.js';
|
|
21
|
-
export * as Text from './util/
|
|
21
|
+
export * as Text from './util/textApi.js';
|
|
22
22
|
export { checkText, checkTextDocument, IncludeExcludeFlag, validateText, } from './validator.js';
|
|
23
23
|
export * from '@cspell/cspell-types';
|
|
24
24
|
export { asyncIterableToArray, readFileText as readFile, readFileTextSync as readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from 'cspell-io';
|
|
@@ -2,7 +2,8 @@ import assert from 'node:assert';
|
|
|
2
2
|
import { opConcatMap, opFilter, pipe } from '@cspell/cspell-pipe/sync';
|
|
3
3
|
import { createCachingDictionary } from 'cspell-dictionary';
|
|
4
4
|
import * as RxPat from '../Settings/RegExpPatterns.js';
|
|
5
|
-
import { extractPossibleWordsFromTextOffset, extractText,
|
|
5
|
+
import { extractPossibleWordsFromTextOffset, extractText, extractWordsFromTextOffset, splitWordWithOffset, } from '../util/text.js';
|
|
6
|
+
import { regExpCamelCaseWordBreaksWithEnglishSuffix } from '../util/textRegex.js';
|
|
6
7
|
import { split } from '../util/wordSplitter.js';
|
|
7
8
|
import { defaultMinWordLength } from './defaultConstants.js';
|
|
8
9
|
import { isWordValidWithEscapeRetry } from './isWordValid.js';
|
|
@@ -149,8 +150,46 @@ export function lineValidatorFactory(sDict, options) {
|
|
|
149
150
|
// English exceptions :-(
|
|
150
151
|
if (isAllCapsWithTrailingCommonEnglishSuffixOk(vr))
|
|
151
152
|
return [];
|
|
153
|
+
if (isWordIgnored(vr.text) || checkWord(vr).isFound) {
|
|
154
|
+
rememberFilter((_) => false)(vr);
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
if (vr.isFlagged)
|
|
158
|
+
return [vr];
|
|
159
|
+
const codeWordResults = checkCamelCaseWord(vr);
|
|
160
|
+
if (!codeWordResults.length) {
|
|
161
|
+
rememberFilter((_) => false)(vr);
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
return codeWordResults;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Break a camel case word into its parts and check each part.
|
|
168
|
+
*
|
|
169
|
+
* There are two word break patterns:
|
|
170
|
+
* - `regExpCamelCaseWordBreaks`
|
|
171
|
+
* - `regExpCamelCaseWordBreaksWithEnglishSuffix` is the default pattern with English suffixes on ALL CAPS words.
|
|
172
|
+
*
|
|
173
|
+
* Note: See [#6066](https://github.com/streetsidesoftware/cspell/pull/6066)
|
|
174
|
+
* Using just `regExpCamelCaseWordBreaks` misses unknown 4-letter words.
|
|
175
|
+
*
|
|
176
|
+
* The code below was tried, but it missed words.
|
|
177
|
+
* - `LSTM` was caught. // cspell:disable-line
|
|
178
|
+
* - `LSTMs` was missed because it becomes `LST` and `Ms`. // cspell:disable-line
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* const results = _checkCamelCaseWord(vr, regExpCamelCaseWordBreaks);
|
|
182
|
+
* if (!results.length) return results;
|
|
183
|
+
* const resultsEnglishBreaks = _checkCamelCaseWord(vr, regExpCamelCaseWordBreaksWithEnglishSuffix);
|
|
184
|
+
* return results.length < resultsEnglishBreaks.length ? results : resultsEnglishBreaks;
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
function checkCamelCaseWord(vr) {
|
|
188
|
+
return _checkCamelCaseWord(vr, regExpCamelCaseWordBreaksWithEnglishSuffix);
|
|
189
|
+
}
|
|
190
|
+
function _checkCamelCaseWord(vr, regExpWordBreaks) {
|
|
152
191
|
const codeWordResults = [];
|
|
153
|
-
for (const wo of
|
|
192
|
+
for (const wo of splitWordWithOffset(vr, regExpWordBreaks)) {
|
|
154
193
|
if (setOfKnownSuccessfulWords.has(wo.text))
|
|
155
194
|
continue;
|
|
156
195
|
const issue = wo;
|
|
@@ -166,10 +205,6 @@ export function lineValidatorFactory(sDict, options) {
|
|
|
166
205
|
issue.text = extractText(lineSegment.segment, issue.offset, issue.offset + issue.text.length);
|
|
167
206
|
codeWordResults.push(issue);
|
|
168
207
|
}
|
|
169
|
-
if (!codeWordResults.length || isWordIgnored(vr.text) || checkWord(vr).isFound) {
|
|
170
|
-
rememberFilter((_) => false)(vr);
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
208
|
return codeWordResults;
|
|
174
209
|
}
|
|
175
210
|
function rebaseKnownIssues(possibleWord, known) {
|
package/dist/lib/util/text.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { TextDocumentOffset, TextOffset } from '@cspell/cspell-types';
|
|
2
2
|
import type { Uri } from './Uri.js';
|
|
3
3
|
export { stringToRegExp } from './textRegex.js';
|
|
4
|
-
export declare function splitCamelCaseWordWithOffset(wo: TextOffset):
|
|
4
|
+
export declare function splitCamelCaseWordWithOffset(wo: TextOffset): TextOffset[];
|
|
5
5
|
/**
|
|
6
6
|
* Split camelCase words into an array of strings.
|
|
7
7
|
*/
|
|
8
8
|
export declare function splitCamelCaseWord(word: string): string[];
|
|
9
|
+
export declare function splitWordWithOffset(wo: TextOffset, regExpWordBreaks: RegExp): TextOffset[];
|
|
10
|
+
/**
|
|
11
|
+
* Split camelCase words into an array of strings.
|
|
12
|
+
*/
|
|
13
|
+
export declare function splitWord(word: string, regExpWordBreaks: RegExp): string[];
|
|
9
14
|
/**
|
|
10
15
|
* This function lets you iterate over regular expression matches.
|
|
11
16
|
*/
|
package/dist/lib/util/text.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { opConcatMap, opMap, pipe } from '@cspell/cspell-pipe/sync';
|
|
2
2
|
import { binarySearch } from './search.js';
|
|
3
|
-
import { regExAccents, regExAllLower, regExAllUpper, regExFirstUpper, regExIgnoreCharacters,
|
|
3
|
+
import { regExAccents, regExAllLower, regExAllUpper, regExFirstUpper, regExIgnoreCharacters, regExpCamelCaseWordBreaksWithEnglishSuffix, regExWords, regExWordsAndDigits, } from './textRegex.js';
|
|
4
4
|
import { toUri } from './Uri.js';
|
|
5
5
|
import { scanMap } from './util.js';
|
|
6
6
|
export { stringToRegExp } from './textRegex.js';
|
|
@@ -15,7 +15,19 @@ export function splitCamelCaseWordWithOffset(wo) {
|
|
|
15
15
|
* Split camelCase words into an array of strings.
|
|
16
16
|
*/
|
|
17
17
|
export function splitCamelCaseWord(word) {
|
|
18
|
-
return word
|
|
18
|
+
return splitWord(word, regExpCamelCaseWordBreaksWithEnglishSuffix);
|
|
19
|
+
}
|
|
20
|
+
export function splitWordWithOffset(wo, regExpWordBreaks) {
|
|
21
|
+
return splitWord(wo.text, regExpWordBreaks).map(scanMap((last, text) => ({ text, offset: last.offset + last.text.length }), {
|
|
22
|
+
text: '',
|
|
23
|
+
offset: wo.offset,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Split camelCase words into an array of strings.
|
|
28
|
+
*/
|
|
29
|
+
export function splitWord(word, regExpWordBreaks) {
|
|
30
|
+
return word.split(regExpWordBreaks);
|
|
19
31
|
}
|
|
20
32
|
/**
|
|
21
33
|
* This function lets you iterate over regular expression matches.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { calculateTextDocumentOffsets, camelToSnake, cleanText, cleanTextOffset, extractLinesOfText, extractPossibleWordsFromTextOffset, extractText, extractWordsFromCode, extractWordsFromCodeTextOffset, extractWordsFromText, extractWordsFromTextOffset, isFirstCharacterLower, isFirstCharacterUpper, isLowerCase, isUpperCase, lcFirst, match, matchCase, matchStringToTextOffset, matchToTextOffset, removeAccents, snakeToCamel, splitCamelCaseWord, splitCamelCaseWordWithOffset, stringToRegExp, textOffset, ucFirst, } from './text.js';
|
|
2
|
+
//# sourceMappingURL=textApi.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { calculateTextDocumentOffsets, camelToSnake, cleanText, cleanTextOffset, extractLinesOfText, extractPossibleWordsFromTextOffset, extractText, extractWordsFromCode, extractWordsFromCodeTextOffset, extractWordsFromText, extractWordsFromTextOffset, isFirstCharacterLower, isFirstCharacterUpper, isLowerCase, isUpperCase, lcFirst, match, matchCase, matchStringToTextOffset, matchToTextOffset, removeAccents, snakeToCamel, splitCamelCaseWord, splitCamelCaseWordWithOffset, stringToRegExp, textOffset, ucFirst, } from './text.js';
|
|
2
|
+
//# sourceMappingURL=textApi.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare const regExUpperSOrIng: RegExp;
|
|
2
2
|
export declare const regExSplitWords: RegExp;
|
|
3
3
|
export declare const regExSplitWords2: RegExp;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const regExpCamelCaseWordBreaksWithEnglishSuffix: RegExp;
|
|
5
|
+
export declare const regExpCamelCaseWordBreaks: RegExp;
|
|
5
6
|
export declare const regExpAllPossibleWordBreaks: RegExp;
|
|
6
7
|
export declare const regExWords: RegExp;
|
|
7
8
|
export declare const regExWordsAndDigits: RegExp;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// cspell:ignore ings ning gimuy anrvtbf gimuxy
|
|
2
2
|
export const regExUpperSOrIng = /([\p{Lu}\p{M}]+(?:\\?['’])?(?:s|ing|ies|es|ings|ed|ning))(?!\p{Ll})/gu;
|
|
3
3
|
export const regExSplitWords = /(\p{Ll}\p{M}?)(\p{Lu})/gu;
|
|
4
|
-
export const regExSplitWords2 = /(\p{Lu}\p{M}?)(\p{Lu}\p{M}
|
|
5
|
-
export const
|
|
4
|
+
export const regExSplitWords2 = /(\p{Lu}\p{M}?)((\p{Lu}\p{M}?)\p{Ll})/gu;
|
|
5
|
+
export const regExpCamelCaseWordBreaksWithEnglishSuffix = /(?<=\p{Ll}\p{M}?)(?=\p{Lu})|(?<=\p{Lu}\p{M}?)(?=\p{Lu}\p{M}?\p{Ll})(?!\p{Lu}\p{M}?(?:s|ing|ies|es|ings|ed|ning)(?!\p{Ll}))/gu;
|
|
6
|
+
export const regExpCamelCaseWordBreaks = /(?<=\p{Ll}\p{M}?)(?=\p{Lu})|(?<=\p{Lu}\p{M}?)(?=\p{Lu}\p{M}?\p{Ll})/gu;
|
|
6
7
|
export const regExpAllPossibleWordBreaks = /(?<=\p{Ll}\p{M}?)(?=\p{Lu})|(?<=\p{Lu}\p{M}?)(?=\p{Lu}\p{M}?\p{Ll})|(?<=\p{Lu}\p{M}?\p{Lu}\p{M}?)(?=\p{Ll})|(?<=\p{L}\p{M}?)(?=\P{L})|(?<=\P{L})(?=\p{L})/gu;
|
|
7
8
|
export const regExWords = /\p{L}\p{M}?(?:(?:\\?['’])?\p{L}\p{M}?)*/gu;
|
|
8
9
|
// Words can be made of letters, numbers, period, underscore, dash, plus, and single quote
|
|
@@ -111,7 +111,7 @@ function genWordBreakCamel(line) {
|
|
|
111
111
|
for (const m of text.matchAll(offsetRegEx(regExSplitWords, line.relStart))) {
|
|
112
112
|
if (m.index === undefined)
|
|
113
113
|
break;
|
|
114
|
-
const i = m.index + 1;
|
|
114
|
+
const i = m.index + m[1].length;
|
|
115
115
|
breaksCamel1.push({
|
|
116
116
|
offset: m.index,
|
|
117
117
|
breaks: [[i, i], ignoreBreak],
|
|
@@ -124,7 +124,7 @@ function genWordBreakCamel(line) {
|
|
|
124
124
|
if (m.index === undefined)
|
|
125
125
|
break;
|
|
126
126
|
const i = m.index + m[1].length;
|
|
127
|
-
const j = i +
|
|
127
|
+
const j = i + m[3].length;
|
|
128
128
|
breaksCamel2.push({
|
|
129
129
|
offset: m.index,
|
|
130
130
|
breaks: [[i, i], [j, j], ignoreBreak],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "8.13.
|
|
3
|
+
"version": "8.13.3",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -58,21 +58,21 @@
|
|
|
58
58
|
},
|
|
59
59
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@cspell/cspell-bundled-dicts": "8.13.
|
|
62
|
-
"@cspell/cspell-pipe": "8.13.
|
|
63
|
-
"@cspell/cspell-resolver": "8.13.
|
|
64
|
-
"@cspell/cspell-types": "8.13.
|
|
65
|
-
"@cspell/dynamic-import": "8.13.
|
|
66
|
-
"@cspell/strong-weak-map": "8.13.
|
|
67
|
-
"@cspell/url": "8.13.
|
|
61
|
+
"@cspell/cspell-bundled-dicts": "8.13.3",
|
|
62
|
+
"@cspell/cspell-pipe": "8.13.3",
|
|
63
|
+
"@cspell/cspell-resolver": "8.13.3",
|
|
64
|
+
"@cspell/cspell-types": "8.13.3",
|
|
65
|
+
"@cspell/dynamic-import": "8.13.3",
|
|
66
|
+
"@cspell/strong-weak-map": "8.13.3",
|
|
67
|
+
"@cspell/url": "8.13.3",
|
|
68
68
|
"clear-module": "^4.1.2",
|
|
69
|
-
"comment-json": "^4.2.
|
|
70
|
-
"cspell-config-lib": "8.13.
|
|
71
|
-
"cspell-dictionary": "8.13.
|
|
72
|
-
"cspell-glob": "8.13.
|
|
73
|
-
"cspell-grammar": "8.13.
|
|
74
|
-
"cspell-io": "8.13.
|
|
75
|
-
"cspell-trie-lib": "8.13.
|
|
69
|
+
"comment-json": "^4.2.5",
|
|
70
|
+
"cspell-config-lib": "8.13.3",
|
|
71
|
+
"cspell-dictionary": "8.13.3",
|
|
72
|
+
"cspell-glob": "8.13.3",
|
|
73
|
+
"cspell-grammar": "8.13.3",
|
|
74
|
+
"cspell-io": "8.13.3",
|
|
75
|
+
"cspell-trie-lib": "8.13.3",
|
|
76
76
|
"env-paths": "^3.0.0",
|
|
77
77
|
"fast-equals": "^5.0.1",
|
|
78
78
|
"gensequence": "^7.0.0",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"lorem-ipsum": "^2.0.8",
|
|
102
102
|
"perf-insight": "^1.2.0"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "e017775a1d181b20abce3c6325f2527a7554a3a9"
|
|
105
105
|
}
|