cspell 7.0.0-alpha.1 → 7.0.1-alpha.0

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.
Files changed (91) hide show
  1. package/dist/esm/application.d.mts +1 -1
  2. package/dist/esm/cli-reporter.mjs +2 -1
  3. package/dist/esm/util/constants.d.mts +1 -1
  4. package/dist/esm/util/fileHelper.d.mts +1 -1
  5. package/dist/lib/file-entry-cache.cjs +3 -2
  6. package/dist/lib/file-entry-cache.d.cts +2 -2
  7. package/dist/lib/pkgInfo.cjs +3 -25
  8. package/package.json +31 -36
  9. package/bin.js +0 -16
  10. package/dist/cjs/app.d.ts +0 -5
  11. package/dist/cjs/app.js +0 -50
  12. package/dist/cjs/application.d.ts +0 -16
  13. package/dist/cjs/application.js +0 -121
  14. package/dist/cjs/cli-reporter.d.ts +0 -16
  15. package/dist/cjs/cli-reporter.js +0 -247
  16. package/dist/cjs/commandCheck.d.ts +0 -3
  17. package/dist/cjs/commandCheck.js +0 -78
  18. package/dist/cjs/commandLink.d.ts +0 -3
  19. package/dist/cjs/commandLink.js +0 -51
  20. package/dist/cjs/commandLint.d.ts +0 -3
  21. package/dist/cjs/commandLint.js +0 -150
  22. package/dist/cjs/commandSuggestion.d.ts +0 -3
  23. package/dist/cjs/commandSuggestion.js +0 -88
  24. package/dist/cjs/commandTrace.d.ts +0 -3
  25. package/dist/cjs/commandTrace.js +0 -87
  26. package/dist/cjs/emitters/DictionaryPathFormat.d.ts +0 -3
  27. package/dist/cjs/emitters/DictionaryPathFormat.js +0 -16
  28. package/dist/cjs/emitters/suggestionsEmitter.d.ts +0 -13
  29. package/dist/cjs/emitters/suggestionsEmitter.js +0 -84
  30. package/dist/cjs/emitters/traceEmitter.d.ts +0 -21
  31. package/dist/cjs/emitters/traceEmitter.js +0 -171
  32. package/dist/cjs/featureFlags/featureFlags.d.ts +0 -4
  33. package/dist/cjs/featureFlags/featureFlags.js +0 -25
  34. package/dist/cjs/featureFlags/index.d.ts +0 -2
  35. package/dist/cjs/featureFlags/index.js +0 -7
  36. package/dist/cjs/index.d.ts +0 -5
  37. package/dist/cjs/index.js +0 -22
  38. package/dist/cjs/link.d.ts +0 -8
  39. package/dist/cjs/link.js +0 -47
  40. package/dist/cjs/lint/LintRequest.d.ts +0 -23
  41. package/dist/cjs/lint/LintRequest.js +0 -48
  42. package/dist/cjs/lint/index.d.ts +0 -3
  43. package/dist/cjs/lint/index.js +0 -8
  44. package/dist/cjs/lint/lint.d.ts +0 -4
  45. package/dist/cjs/lint/lint.js +0 -499
  46. package/dist/cjs/options.d.ts +0 -178
  47. package/dist/cjs/options.js +0 -12
  48. package/dist/cjs/repl/index.d.ts +0 -18
  49. package/dist/cjs/repl/index.js +0 -75
  50. package/dist/cjs/util/InMemoryReporter.d.ts +0 -28
  51. package/dist/cjs/util/InMemoryReporter.js +0 -47
  52. package/dist/cjs/util/async.d.ts +0 -3
  53. package/dist/cjs/util/async.js +0 -12
  54. package/dist/cjs/util/cache/CSpellLintResultCache.d.ts +0 -20
  55. package/dist/cjs/util/cache/CSpellLintResultCache.js +0 -3
  56. package/dist/cjs/util/cache/CacheOptions.d.ts +0 -34
  57. package/dist/cjs/util/cache/CacheOptions.js +0 -3
  58. package/dist/cjs/util/cache/DiskCache.d.ts +0 -63
  59. package/dist/cjs/util/cache/DiskCache.js +0 -237
  60. package/dist/cjs/util/cache/DummyCache.d.ts +0 -11
  61. package/dist/cjs/util/cache/DummyCache.js +0 -22
  62. package/dist/cjs/util/cache/ObjectCollection.d.ts +0 -17
  63. package/dist/cjs/util/cache/ObjectCollection.js +0 -136
  64. package/dist/cjs/util/cache/createCache.d.ts +0 -31
  65. package/dist/cjs/util/cache/createCache.js +0 -77
  66. package/dist/cjs/util/cache/fileEntryCache.d.ts +0 -9
  67. package/dist/cjs/util/cache/fileEntryCache.js +0 -107
  68. package/dist/cjs/util/cache/index.d.ts +0 -4
  69. package/dist/cjs/util/cache/index.js +0 -8
  70. package/dist/cjs/util/constants.d.ts +0 -6
  71. package/dist/cjs/util/constants.js +0 -8
  72. package/dist/cjs/util/errors.d.ts +0 -23
  73. package/dist/cjs/util/errors.js +0 -60
  74. package/dist/cjs/util/fileHelper.d.ts +0 -63
  75. package/dist/cjs/util/fileHelper.js +0 -226
  76. package/dist/cjs/util/glob.d.ts +0 -45
  77. package/dist/cjs/util/glob.js +0 -175
  78. package/dist/cjs/util/prefetch.d.ts +0 -2
  79. package/dist/cjs/util/prefetch.js +0 -23
  80. package/dist/cjs/util/reporters.d.ts +0 -14
  81. package/dist/cjs/util/reporters.js +0 -68
  82. package/dist/cjs/util/stdin.d.ts +0 -2
  83. package/dist/cjs/util/stdin.js +0 -32
  84. package/dist/cjs/util/table.d.ts +0 -10
  85. package/dist/cjs/util/table.js +0 -40
  86. package/dist/cjs/util/timer.d.ts +0 -8
  87. package/dist/cjs/util/timer.js +0 -17
  88. package/dist/cjs/util/types.d.ts +0 -7
  89. package/dist/cjs/util/types.js +0 -6
  90. package/dist/cjs/util/util.d.ts +0 -13
  91. package/dist/cjs/util/util.js +0 -55
@@ -1,499 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.runLint = void 0;
30
- const cspell_pipe_1 = require("@cspell/cspell-pipe");
31
- const sync_1 = require("@cspell/cspell-pipe/sync");
32
- const cspell_types_1 = require("@cspell/cspell-types");
33
- const chalk_1 = __importDefault(require("chalk"));
34
- const cspell_gitignore_1 = require("cspell-gitignore");
35
- const cspell_glob_1 = require("cspell-glob");
36
- const cspell = __importStar(require("cspell-lib"));
37
- const path = __importStar(require("path"));
38
- const util_1 = require("util");
39
- const pkgInfo_cjs_1 = require("../../lib/pkgInfo.cjs");
40
- const uri_cjs_1 = require("../../lib/uri.cjs");
41
- const index_js_1 = require("../featureFlags/index.js");
42
- const index_js_2 = require("../util/cache/index.js");
43
- const errors_js_1 = require("../util/errors.js");
44
- const fileHelper_js_1 = require("../util/fileHelper.js");
45
- const glob_js_1 = require("../util/glob.js");
46
- const prefetch_js_1 = require("../util/prefetch.js");
47
- const reporters_js_1 = require("../util/reporters.js");
48
- const timer_js_1 = require("../util/timer.js");
49
- const util = __importStar(require("../util/util.js"));
50
- const version = pkgInfo_cjs_1.npmPackage.version;
51
- const BATCH_SIZE = 8;
52
- const { opFilterAsync } = cspell_pipe_1.operators;
53
- async function runLint(cfg) {
54
- let { reporter } = cfg;
55
- cspell.setLogger(getLoggerFromReporter(reporter));
56
- const configErrors = new Set();
57
- const timer = (0, timer_js_1.getTimeMeasurer)();
58
- const lintResult = await run();
59
- await reporter.result(lintResult);
60
- const elapsed = timer();
61
- if ((0, index_js_1.getFeatureFlags)().getFlag('timer')) {
62
- console.log(`Elapsed Time: ${elapsed.toFixed(2)}ms`);
63
- }
64
- return lintResult;
65
- function prefetch(filename, configInfo, cache) {
66
- if ((0, fileHelper_js_1.isBinaryFile)(filename, cfg.root))
67
- return { filename, result: Promise.resolve({ skip: true }) };
68
- async function fetch() {
69
- const getElapsedTimeMs = (0, timer_js_1.getTimeMeasurer)();
70
- const cachedResult = await cache.getCachedLintResults(filename);
71
- if (cachedResult) {
72
- reporter.debug(`Filename: ${filename}, using cache`);
73
- const fileResult = { ...cachedResult, elapsedTimeMs: getElapsedTimeMs() };
74
- return { fileResult };
75
- }
76
- const uri = (0, fileHelper_js_1.filenameToUri)(filename, cfg.root);
77
- const checkResult = await cspell.shouldCheckDocument({ uri }, {}, configInfo.config);
78
- if (!checkResult.shouldCheck)
79
- return { skip: true };
80
- const fileInfo = await (0, fileHelper_js_1.readFileInfo)(filename, undefined, true);
81
- return { fileInfo };
82
- }
83
- const result = fetch();
84
- return { filename, result };
85
- }
86
- async function processFile(filename, configInfo, cache, prefetch) {
87
- if (prefetch?.fileResult)
88
- return prefetch.fileResult;
89
- const getElapsedTimeMs = (0, timer_js_1.getTimeMeasurer)();
90
- const cachedResult = await cache.getCachedLintResults(filename);
91
- if (cachedResult) {
92
- reporter.debug(`Filename: ${filename}, using cache`);
93
- return { ...cachedResult, elapsedTimeMs: getElapsedTimeMs() };
94
- }
95
- const result = {
96
- fileInfo: {
97
- filename,
98
- },
99
- issues: [],
100
- processed: false,
101
- errors: 0,
102
- configErrors: 0,
103
- elapsedTimeMs: 0,
104
- };
105
- const fileInfo = prefetch?.fileInfo || (await (0, fileHelper_js_1.readFileInfo)(filename, undefined, true));
106
- if (fileInfo.errorCode) {
107
- if (fileInfo.errorCode !== 'EISDIR' && cfg.options.mustFindFiles) {
108
- const err = (0, errors_js_1.toError)(`File not found: "${filename}"`);
109
- reporter.error('Linter:', err);
110
- result.errors += 1;
111
- }
112
- return result;
113
- }
114
- const doc = (0, fileHelper_js_1.fileInfoToDocument)(fileInfo, cfg.options.languageId, cfg.locale);
115
- const { text } = fileInfo;
116
- result.fileInfo = fileInfo;
117
- let spellResult = {};
118
- reporter.info(`Checking: ${filename}, File type: ${doc.languageId ?? 'auto'}, Language: ${doc.locale ?? 'default'}`, cspell_types_1.MessageTypes.Info);
119
- try {
120
- const { showSuggestions: generateSuggestions, validateDirectives } = cfg.options;
121
- const numSuggestions = configInfo.config.numSuggestions ?? 5;
122
- const validateOptions = util.clean({ generateSuggestions, numSuggestions, validateDirectives });
123
- const r = await cspell.spellCheckDocument(doc, validateOptions, configInfo.config);
124
- spellResult = r;
125
- result.processed = r.checked;
126
- result.issues = cspell.Text.calculateTextDocumentOffsets(doc.uri, text, r.issues).map(mapIssue);
127
- }
128
- catch (e) {
129
- reporter.error(`Failed to process "${filename}"`, (0, errors_js_1.toError)(e));
130
- result.errors += 1;
131
- }
132
- result.elapsedTimeMs = getElapsedTimeMs();
133
- const config = spellResult.settingsUsed ?? {};
134
- result.configErrors += await reportConfigurationErrors(config);
135
- const elapsed = result.elapsedTimeMs / 1000.0;
136
- const dictionaries = config.dictionaries || [];
137
- reporter.info(`Checked: ${filename}, File type: ${config.languageId}, Language: ${config.language} ... Issues: ${result.issues.length} ${elapsed}S`, cspell_types_1.MessageTypes.Info);
138
- reporter.info(`Config file Used: ${spellResult.localConfigFilepath || configInfo.source}`, cspell_types_1.MessageTypes.Info);
139
- reporter.info(`Dictionaries Used: ${dictionaries.join(', ')}`, cspell_types_1.MessageTypes.Info);
140
- if (cfg.options.debug) {
141
- const { id: _id, name: _name, __imports, __importRef, ...cfg } = config;
142
- const debugCfg = {
143
- filename,
144
- languageId: doc.languageId ?? cfg.languageId ?? 'default',
145
- config: { ...cfg, source: null },
146
- source: spellResult.localConfigFilepath,
147
- };
148
- reporter.debug(JSON.stringify(debugCfg, undefined, 2));
149
- }
150
- const dep = calcDependencies(config);
151
- cache.setCachedLintResults(result, dep.files);
152
- return result;
153
- }
154
- function mapIssue({ doc: _, ...tdo }) {
155
- const context = cfg.showContext
156
- ? extractContext(tdo, cfg.showContext)
157
- : { text: tdo.line.text.trimEnd(), offset: tdo.line.offset };
158
- return util.clean({ ...tdo, context });
159
- }
160
- async function processFiles(files, configInfo, cacheSettings) {
161
- const fileCount = files instanceof Array ? files.length : undefined;
162
- const status = runResult();
163
- const cache = (0, index_js_2.createCache)(cacheSettings);
164
- const failFast = cfg.options.failFast ?? configInfo.config.failFast ?? false;
165
- const emitProgressBegin = (filename, fileNum, fileCount) => reporter.progress({
166
- type: 'ProgressFileBegin',
167
- fileNum,
168
- fileCount,
169
- filename,
170
- });
171
- const emitProgressComplete = (filename, fileNum, fileCount, result) => reporter.progress(util.clean({
172
- type: 'ProgressFileComplete',
173
- fileNum,
174
- fileCount,
175
- filename,
176
- elapsedTimeMs: result?.elapsedTimeMs,
177
- processed: result?.processed,
178
- numErrors: result?.issues.length || result?.errors,
179
- cached: result?.cached,
180
- }));
181
- function* prefetchFiles(files) {
182
- const iter = (0, prefetch_js_1.prefetchIterable)((0, sync_1.pipe)(files, (0, sync_1.opMap)((filename) => prefetch(filename, configInfo, cache))), BATCH_SIZE);
183
- for (const v of iter) {
184
- yield v;
185
- }
186
- }
187
- async function* prefetchFilesAsync(files) {
188
- for await (const filename of files) {
189
- yield prefetch(filename, configInfo, cache);
190
- }
191
- }
192
- const emptyResult = {
193
- fileInfo: { filename: '' },
194
- issues: [],
195
- processed: false,
196
- errors: 0,
197
- configErrors: 0,
198
- elapsedTimeMs: 1,
199
- };
200
- async function processPrefetchFileResult(pf, index) {
201
- const { filename, result: pFetchResult } = pf;
202
- const getElapsedTimeMs = (0, timer_js_1.getTimeMeasurer)();
203
- const fetchResult = await pFetchResult;
204
- emitProgressBegin(filename, index, fileCount ?? index);
205
- if (fetchResult?.skip) {
206
- return {
207
- filename,
208
- fileNum: index,
209
- result: { ...emptyResult, fileInfo: { filename }, elapsedTimeMs: getElapsedTimeMs() },
210
- };
211
- }
212
- const result = await processFile(filename, configInfo, cache, fetchResult);
213
- return { filename, fileNum: index, result };
214
- }
215
- async function* loadAndProcessFiles() {
216
- let i = 0;
217
- if ((0, cspell_pipe_1.isAsyncIterable)(files)) {
218
- for await (const pf of prefetchFilesAsync(files)) {
219
- yield processPrefetchFileResult(pf, ++i);
220
- }
221
- }
222
- else {
223
- for (const pf of prefetchFiles(files)) {
224
- await pf.result;
225
- yield await processPrefetchFileResult(pf, ++i);
226
- }
227
- }
228
- }
229
- for await (const fileP of loadAndProcessFiles()) {
230
- const { filename, fileNum, result } = await fileP;
231
- status.files += 1;
232
- status.cachedFiles = (status.cachedFiles || 0) + (result.cached ? 1 : 0);
233
- emitProgressComplete(filename, fileNum, fileCount ?? fileNum, result);
234
- // Show the spelling errors after emitting the progress.
235
- result.issues.filter(cfg.uniqueFilter).forEach((issue) => reporter.issue(issue));
236
- if (result.issues.length || result.errors) {
237
- status.filesWithIssues.add(filename);
238
- status.issues += result.issues.length;
239
- status.errors += result.errors;
240
- if (failFast) {
241
- return status;
242
- }
243
- }
244
- status.errors += result.configErrors;
245
- }
246
- cache.reconcile();
247
- return status;
248
- }
249
- function calcDependencies(config) {
250
- const { configFiles, dictionaryFiles } = cspell.extractDependencies(config);
251
- return { files: configFiles.concat(dictionaryFiles) };
252
- }
253
- async function reportConfigurationErrors(config) {
254
- const errors = cspell.extractImportErrors(config);
255
- let count = 0;
256
- errors.forEach((ref) => {
257
- const key = ref.error.toString();
258
- if (configErrors.has(key))
259
- return;
260
- configErrors.add(key);
261
- count += 1;
262
- reporter.error('Configuration', ref.error);
263
- });
264
- const dictCollection = await cspell.getDictionary(config);
265
- dictCollection.dictionaries.forEach((dict) => {
266
- const dictErrors = dict.getErrors?.() || [];
267
- const msg = `Dictionary Error with (${dict.name})`;
268
- dictErrors.forEach((error) => {
269
- const key = msg + error.toString();
270
- if (configErrors.has(key))
271
- return;
272
- configErrors.add(key);
273
- count += 1;
274
- reporter.error(msg, error);
275
- });
276
- });
277
- return count;
278
- }
279
- function countConfigErrors(configInfo) {
280
- return reportConfigurationErrors(configInfo.config);
281
- }
282
- async function run() {
283
- if (cfg.options.root) {
284
- process.env[cspell.ENV_CSPELL_GLOB_ROOT] = cfg.root;
285
- }
286
- const configInfo = await (0, fileHelper_js_1.readConfig)(cfg.configFile, cfg.root);
287
- if (cfg.options.defaultConfiguration !== undefined) {
288
- configInfo.config.loadDefaultConfiguration = cfg.options.defaultConfiguration;
289
- }
290
- const reporterConfig = util.clean({
291
- maxNumberOfProblems: configInfo.config.maxNumberOfProblems,
292
- maxDuplicateProblems: configInfo.config.maxDuplicateProblems,
293
- minWordLength: configInfo.config.minWordLength,
294
- ...cfg.options,
295
- });
296
- const reporters = cfg.options.reporter ?? configInfo.config.reporters;
297
- reporter = (0, reporters_js_1.mergeReporters)(...(await (0, reporters_js_1.loadReporters)(reporters, cfg.reporter, reporterConfig)));
298
- cspell.setLogger(getLoggerFromReporter(reporter));
299
- const globInfo = await determineGlobs(configInfo, cfg);
300
- const { fileGlobs, excludeGlobs } = globInfo;
301
- const hasFileLists = !!cfg.fileLists.length;
302
- if (!fileGlobs.length && !hasFileLists) {
303
- // Nothing to do.
304
- return runResult();
305
- }
306
- header(fileGlobs, excludeGlobs);
307
- checkGlobs(fileGlobs, reporter);
308
- reporter.info(`Config Files Found:\n ${configInfo.source}\n`, cspell_types_1.MessageTypes.Info);
309
- const configErrors = await countConfigErrors(configInfo);
310
- if (configErrors)
311
- return runResult({ errors: configErrors });
312
- // Get Exclusions from the config files.
313
- const { root } = cfg;
314
- try {
315
- const cacheSettings = await (0, index_js_2.calcCacheSettings)(configInfo.config, { ...cfg.options, version }, root);
316
- const files = await determineFilesToCheck(configInfo, cfg, reporter, globInfo);
317
- return await processFiles(files, configInfo, cacheSettings);
318
- }
319
- catch (e) {
320
- const err = (0, errors_js_1.toApplicationError)(e);
321
- reporter.error('Linter', err);
322
- return runResult({ errors: 1 });
323
- }
324
- }
325
- function header(files, cliExcludes) {
326
- const formattedFiles = files.length > 100 ? files.slice(0, 100).concat(['...']) : files;
327
- reporter.info(`
328
- cspell;
329
- Date: ${new Date().toUTCString()}
330
- Options:
331
- verbose: ${yesNo(!!cfg.options.verbose)}
332
- config: ${cfg.configFile || 'default'}
333
- exclude: ${cliExcludes.join('\n ')}
334
- files: ${formattedFiles}
335
- wordsOnly: ${yesNo(!!cfg.options.wordsOnly)}
336
- unique: ${yesNo(!!cfg.options.unique)}
337
- `, cspell_types_1.MessageTypes.Info);
338
- }
339
- }
340
- exports.runLint = runLint;
341
- function checkGlobs(globs, reporter) {
342
- globs
343
- .filter((g) => g.startsWith("'") || g.endsWith("'"))
344
- .map((glob) => chalk_1.default.yellow(glob))
345
- .forEach((glob) => reporter.error('Linter', new errors_js_1.CheckFailed(`Glob starting or ending with ' (single quote) is not likely to match any files: ${glob}.`)));
346
- }
347
- async function determineGlobs(configInfo, cfg) {
348
- const useGitignore = cfg.options.gitignore ?? configInfo.config.useGitignore ?? false;
349
- const gitignoreRoots = cfg.options.gitignoreRoot ?? configInfo.config.gitignoreRoot;
350
- const gitIgnore = useGitignore ? await generateGitIgnore(gitignoreRoots) : undefined;
351
- const cliGlobs = cfg.fileGlobs;
352
- const allGlobs = cliGlobs.length ? cliGlobs : configInfo.config.files || [];
353
- const combinedGlobs = await (0, glob_js_1.normalizeFileOrGlobsToRoot)(allGlobs, cfg.root);
354
- const cliExcludeGlobs = (0, glob_js_1.extractPatterns)(cfg.excludes).map((p) => p.glob);
355
- const normalizedExcludes = (0, glob_js_1.normalizeGlobsToRoot)(cliExcludeGlobs, cfg.root, true);
356
- const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
357
- const excludeGlobs = combinedGlobs.filter((g) => g.startsWith('!')).concat(normalizedExcludes);
358
- const fileGlobs = includeGlobs;
359
- const appGlobs = { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes };
360
- return appGlobs;
361
- }
362
- async function determineFilesToCheck(configInfo, cfg, reporter, globInfo) {
363
- async function _determineFilesToCheck() {
364
- const { fileLists } = cfg;
365
- const hasFileLists = !!fileLists.length;
366
- const { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes } = globInfo;
367
- // Get Exclusions from the config files.
368
- const { root } = cfg;
369
- const globsToExclude = (configInfo.config.ignorePaths || []).concat(excludeGlobs);
370
- const globMatcher = (0, glob_js_1.buildGlobMatcher)(globsToExclude, root, true);
371
- const ignoreGlobs = (0, glob_js_1.extractGlobsFromMatcher)(globMatcher);
372
- // cspell:word nodir
373
- const globOptions = {
374
- root,
375
- cwd: root,
376
- ignore: ignoreGlobs.concat(normalizedExcludes),
377
- nodir: true,
378
- };
379
- const enableGlobDot = cfg.enableGlobDot ?? configInfo.config.enableGlobDot;
380
- if (enableGlobDot !== undefined) {
381
- globOptions.dot = enableGlobDot;
382
- }
383
- const filterFiles = (0, cspell_pipe_1.opFilter)(filterFilesFn(globMatcher));
384
- const foundFiles = await (hasFileLists
385
- ? useFileLists(fileLists, allGlobs, root, enableGlobDot)
386
- : (0, fileHelper_js_1.findFiles)(fileGlobs, globOptions));
387
- const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles;
388
- const files = (0, cspell_pipe_1.isAsyncIterable)(filtered)
389
- ? (0, cspell_pipe_1.pipeAsync)(filtered, filterFiles)
390
- : [...(0, cspell_pipe_1.pipeSync)(filtered, filterFiles)];
391
- return files;
392
- }
393
- function isExcluded(filename, globMatcherExclude) {
394
- if (cspell.isBinaryFile(uri_cjs_1.URI.file(filename))) {
395
- return true;
396
- }
397
- const { root } = cfg;
398
- const absFilename = path.resolve(root, filename);
399
- const r = globMatcherExclude.matchEx(absFilename);
400
- if (r.matched) {
401
- const { glob, source } = extractGlobSource(r.pattern);
402
- reporter.info(`Excluded File: ${path.relative(root, absFilename)}; Excluded by ${glob} from ${source}`, cspell_types_1.MessageTypes.Info);
403
- }
404
- return r.matched;
405
- }
406
- function filterFilesFn(globMatcherExclude) {
407
- const patterns = globMatcherExclude.patterns;
408
- const excludeInfo = patterns
409
- .map(extractGlobSource)
410
- .map(({ glob, source }) => `Glob: ${glob} from ${source}`)
411
- .filter(util.uniqueFn());
412
- reporter.info(`Exclusion Globs: \n ${excludeInfo.join('\n ')}\n`, cspell_types_1.MessageTypes.Info);
413
- return (filename) => !isExcluded(filename, globMatcherExclude);
414
- }
415
- return _determineFilesToCheck();
416
- }
417
- function extractContext(tdo, contextRange) {
418
- const { line, offset } = tdo;
419
- const textOffsetInLine = offset - line.offset;
420
- let left = Math.max(textOffsetInLine - contextRange, 0);
421
- let right = Math.min(line.text.length, textOffsetInLine + contextRange + tdo.text.length);
422
- const lineText = line.text;
423
- const isLetter = /^[a-z]$/i;
424
- const isSpace = /^\s$/;
425
- for (let n = contextRange / 2; n > 0 && left > 0; n--, left--) {
426
- if (!isLetter.test(lineText[left - 1])) {
427
- break;
428
- }
429
- }
430
- for (let n = contextRange / 2; n > 0 && right < lineText.length; n--, right++) {
431
- if (!isLetter.test(lineText[right])) {
432
- break;
433
- }
434
- }
435
- // remove leading space
436
- for (; left < textOffsetInLine && isSpace.test(lineText[left]); left++) {
437
- /* do nothing */
438
- }
439
- const context = {
440
- text: line.text.slice(left, right).trimEnd(),
441
- offset: left + line.offset,
442
- };
443
- return context;
444
- }
445
- function extractGlobSource(g) {
446
- const { glob, rawGlob, source } = g;
447
- return {
448
- glob: rawGlob || glob,
449
- source,
450
- };
451
- }
452
- function runResult(init = {}) {
453
- const { files = 0, filesWithIssues = new Set(), issues = 0, errors = 0, cachedFiles = 0 } = init;
454
- return { files, filesWithIssues, issues, errors, cachedFiles };
455
- }
456
- function yesNo(value) {
457
- return value ? 'Yes' : 'No';
458
- }
459
- function getLoggerFromReporter(reporter) {
460
- const log = (...params) => {
461
- const msg = (0, util_1.format)(...params);
462
- reporter.info(msg, 'Info');
463
- };
464
- const error = (...params) => {
465
- const msg = (0, util_1.format)(...params);
466
- const err = { message: '', name: 'error', toString: () => '' };
467
- reporter.error(msg, err);
468
- };
469
- const warn = (...params) => {
470
- const msg = (0, util_1.format)(...params);
471
- reporter.info(msg, 'Warning');
472
- };
473
- return {
474
- log,
475
- warn,
476
- error,
477
- };
478
- }
479
- async function generateGitIgnore(roots) {
480
- const root = (typeof roots === 'string' ? [roots].filter((r) => !!r) : roots) || [];
481
- if (!root?.length) {
482
- const cwd = process.cwd();
483
- const repo = (await (0, cspell_gitignore_1.findRepoRoot)(cwd)) || cwd;
484
- root.push(repo);
485
- }
486
- return new cspell_gitignore_1.GitIgnore(root?.map((p) => path.resolve(p)));
487
- }
488
- async function useFileLists(fileListFiles, includeGlobPatterns, root, dot) {
489
- includeGlobPatterns = includeGlobPatterns.length ? includeGlobPatterns : ['**'];
490
- const options = { root, mode: 'include' };
491
- if (dot !== undefined) {
492
- options.dot = dot;
493
- }
494
- const globMatcher = new cspell_glob_1.GlobMatcher(includeGlobPatterns, options);
495
- const filterFiles = (file) => globMatcher.match(file);
496
- const files = (0, fileHelper_js_1.readFileListFiles)(fileListFiles);
497
- return (0, cspell_pipe_1.pipeAsync)(files, (0, cspell_pipe_1.opFilter)(filterFiles), opFilterAsync(fileHelper_js_1.isNotDir));
498
- }
499
- //# sourceMappingURL=lint.js.map
@@ -1,178 +0,0 @@
1
- import type { CacheOptions } from './util/cache/index.js';
2
- export interface LinterOptions extends BaseOptions, Omit<CacheOptions, 'version'> {
3
- /**
4
- * Display verbose information
5
- */
6
- verbose?: boolean;
7
- /**
8
- * Show extensive output.
9
- */
10
- debug?: boolean;
11
- /**
12
- * a globs to exclude files from being checked.
13
- */
14
- exclude?: string[] | string;
15
- /**
16
- * Only report the words, no line numbers or file names.
17
- */
18
- wordsOnly?: boolean;
19
- /**
20
- * unique errors per file only.
21
- */
22
- unique?: boolean;
23
- /**
24
- * root directory, defaults to `cwd`
25
- */
26
- root?: string;
27
- /**
28
- * Determine if files / directories starting with `.` should be part
29
- * of the glob search.
30
- * @default false
31
- */
32
- dot?: boolean;
33
- /**
34
- * Show part of a line where an issue is found.
35
- * if true, it will show the default number of characters on either side.
36
- * if a number, it will shat number of characters on either side.
37
- */
38
- showContext?: boolean | number;
39
- /**
40
- * Show suggestions for spelling errors.
41
- */
42
- showSuggestions?: boolean;
43
- /**
44
- * Enable filtering out files matching globs found in `.gitignore` files.
45
- */
46
- gitignore?: boolean;
47
- /**
48
- * Stop searching for a `.gitignore`s when a root is reached.
49
- */
50
- gitignoreRoot?: string | string[];
51
- /**
52
- * List of files that contains the paths to files to be spell checked.
53
- * The files in the lists will be filtered against the glob patterns.
54
- * - an entry of `stdin` means to read the file list from **`stdin`**
55
- */
56
- fileList?: string[] | undefined;
57
- /**
58
- * Files must be found and processed otherwise it is considered an error.
59
- */
60
- mustFindFiles?: boolean;
61
- /**
62
- * Stop processing and exit if an issue or error is found.
63
- */
64
- failFast?: boolean;
65
- /**
66
- * Optional list of reporters to use, overriding any specified in the
67
- * configuration.
68
- */
69
- reporter?: string[];
70
- }
71
- export interface TraceOptions extends BaseOptions {
72
- stdin?: boolean;
73
- allowCompoundWords?: boolean;
74
- ignoreCase?: boolean;
75
- all?: boolean;
76
- onlyFound?: boolean;
77
- dictionaryPath?: 'hide' | 'long' | 'short' | 'full';
78
- }
79
- export interface SuggestionOptions extends BaseOptions {
80
- /**
81
- * Strict case and accent checking
82
- * @default true
83
- */
84
- strict?: boolean;
85
- /**
86
- * List of dictionaries to use. If specified, only that list of dictionaries will be used.
87
- */
88
- dictionaries?: string[] | undefined;
89
- /**
90
- * The number of suggestions to make.
91
- * @default 8
92
- */
93
- numSuggestions?: number;
94
- /**
95
- * Max number of changes / edits to the word to get to a suggestion matching suggestion.
96
- * @default 4
97
- */
98
- numChanges?: number;
99
- /**
100
- * If multiple suggestions have the same edit / change "cost", then included them even if
101
- * it causes more than `numSuggestions` to be returned.
102
- * @default true
103
- */
104
- includeTies?: boolean;
105
- /**
106
- * Use stdin for the input
107
- */
108
- useStdin?: boolean | undefined;
109
- /**
110
- * Use REPL interface for making suggestions.
111
- */
112
- repl?: boolean;
113
- }
114
- export interface LegacyOptions {
115
- local?: string;
116
- }
117
- export interface BaseOptions {
118
- /**
119
- * Path to configuration file.
120
- */
121
- config?: string;
122
- /**
123
- * Programming Language ID.
124
- */
125
- languageId?: string;
126
- /**
127
- * Locale to use.
128
- */
129
- locale?: string;
130
- /**
131
- * Load the default configuration
132
- * @default true
133
- */
134
- defaultConfiguration?: boolean;
135
- /**
136
- * Check In-Document CSpell directives for correctness.
137
- */
138
- validateDirectives?: boolean;
139
- /**
140
- * Execution flags.
141
- * Used primarily for releasing experimental features.
142
- * Flags are of the form key:value
143
- */
144
- flag?: string[];
145
- }
146
- export interface LinterCliOptions extends LinterOptions {
147
- /**
148
- * Show legacy output
149
- */
150
- legacy?: boolean;
151
- /**
152
- * Show summary at the end
153
- */
154
- summary?: boolean;
155
- /**
156
- * Show issues
157
- */
158
- issues?: boolean;
159
- /**
160
- * Run in silent mode.
161
- * @default false
162
- */
163
- silent?: boolean;
164
- /**
165
- * Show progress
166
- */
167
- progress?: boolean;
168
- /**
169
- * issues are shown with a relative path to the root or `cwd`
170
- */
171
- relative?: boolean;
172
- /**
173
- * Files must be found or cli will exit with an error.
174
- */
175
- mustFindFiles?: boolean;
176
- }
177
- export declare function fixLegacy<T extends BaseOptions>(opts: T & LegacyOptions): Omit<T & LegacyOptions, 'local'>;
178
- //# sourceMappingURL=options.d.ts.map
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixLegacy = void 0;
4
- function fixLegacy(opts) {
5
- const { local, ...rest } = opts;
6
- if (local && !rest.locale) {
7
- rest.locale = local;
8
- }
9
- return rest;
10
- }
11
- exports.fixLegacy = fixLegacy;
12
- //# sourceMappingURL=options.js.map