cspell 5.17.0 → 5.18.2

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.
@@ -24,7 +24,7 @@ const cspell_lib_1 = require("cspell-lib");
24
24
  const path = __importStar(require("path"));
25
25
  const lint_1 = require("./lint");
26
26
  const options_1 = require("./options");
27
- const async = __importStar(require("./util/async"));
27
+ const async = __importStar(require("@cspell/cspell-pipe"));
28
28
  const fileHelper_1 = require("./util/fileHelper");
29
29
  const stdin_1 = require("./util/stdin");
30
30
  const util = __importStar(require("./util/util"));
@@ -38,7 +38,7 @@ function lint(fileGlobs, options, emitters) {
38
38
  exports.lint = lint;
39
39
  async function* trace(words, options) {
40
40
  options = (0, options_1.fixLegacy)(options);
41
- const iWords = options.stdin ? async.mergeAsyncIterables(words, (0, stdin_1.readStdin)()) : words;
41
+ const iWords = options.stdin ? async.toAsyncIterable(words, (0, stdin_1.readStdin)()) : words;
42
42
  const { languageId, locale, allowCompoundWords, ignoreCase } = options;
43
43
  const configFile = await (0, fileHelper_1.readConfig)(options.config, undefined);
44
44
  const config = (0, cspell_lib_1.mergeSettings)((0, cspell_lib_1.getDefaultSettings)(), (0, cspell_lib_1.getGlobalSettings)(), configFile.config);
@@ -60,7 +60,7 @@ exports.checkText = checkText;
60
60
  async function* suggestions(words, options) {
61
61
  options = (0, options_1.fixLegacy)(options);
62
62
  const configFile = await (0, fileHelper_1.readConfig)(options.config, undefined);
63
- const iWords = options.useStdin ? async.mergeAsyncIterables(words, (0, stdin_1.readStdin)()) : words;
63
+ const iWords = options.useStdin ? async.toAsyncIterable(words, (0, stdin_1.readStdin)()) : words;
64
64
  try {
65
65
  const results = (0, cspell_lib_1.suggestionsForWords)(iWords, options, configFile.config);
66
66
  yield* results;
@@ -6,21 +6,24 @@ const util_1 = require("../util/util");
6
6
  function emitSuggestionResult(result, options) {
7
7
  const { word, suggestions } = result;
8
8
  const { verbose, output = console } = options;
9
- output.log(word ? chalk.green(word) : chalk.yellow('<empty>') + ':');
9
+ output.log(word ? chalk.yellow(word) : chalk.yellow('<empty>') + ':');
10
10
  if (!suggestions.length) {
11
11
  console.log(chalk.yellow(' <no suggestions>'));
12
12
  return;
13
13
  }
14
14
  if (verbose) {
15
- const maxWidth = suggestions.map((r) => r.word.length).reduce((max, len) => Math.max(max, len), 0);
15
+ const maxWidth = suggestions
16
+ .map((r) => (0, util_1.width)(r.compoundWord || r.word))
17
+ .reduce((max, len) => Math.max(max, len), 0);
16
18
  for (const sug of suggestions) {
17
- const { word, cost, dictionaries } = sug;
18
- const padding = ' '.repeat(maxWidth - word.length);
19
+ const { word, cost, dictionaries, compoundWord } = sug;
20
+ const w = compoundWord || word;
21
+ const padding = ' '.repeat((0, util_1.padWidth)(w, maxWidth));
19
22
  const forbid = sug.forbidden ? chalk.red('X') : ' ';
20
23
  const ignore = sug.noSuggest ? chalk.yellow('N') : ' ';
21
24
  const strCost = (0, util_1.padLeft)(cost.toString(10), 4);
22
25
  const dicts = dictionaries.map((n) => chalk.gray(n)).join(', ');
23
- output.log(` - ${formatWord(word, sug)}${padding} ${forbid}${ignore} - ${chalk.yellow(strCost)} ${dicts}`);
26
+ output.log(` - ${formatWord(w, sug)}${padding} ${forbid}${ignore} - ${chalk.yellow(strCost)} ${dicts}`);
24
27
  }
25
28
  }
26
29
  else {
@@ -32,7 +32,7 @@ function emitTraceResults(results, options) {
32
32
  var _a;
33
33
  const maxWordLength = results
34
34
  .map((r) => r.foundWord || r.word)
35
- .reduce((a, b) => Math.max(a, b.length), 'Word'.length);
35
+ .reduce((a, b) => Math.max(a, (0, util_1.width)(b)), 'Word'.length);
36
36
  const cols = {
37
37
  word: maxWordLength,
38
38
  dictName: colWidthDictionaryName,
@@ -66,7 +66,7 @@ function emitTraceResult(r, colWidths, options) {
66
66
  const dictColor = r.dictActive ? chalk.yellowBright : chalk.rgb(200, 128, 50);
67
67
  const n = dictColor(dictName);
68
68
  const info = [w, f, n].join(' ') + ' ';
69
- const used = (0, strip_ansi_1.default)(info).length;
69
+ const used = (0, util_1.width)((0, strip_ansi_1.default)(info));
70
70
  const widthSrc = terminalWidth - used;
71
71
  const c = errors ? chalk.red : chalk.white;
72
72
  const s = c(formatDictionaryLocation(r.dictSource, widthSrc, options.cwd));
package/dist/lint/lint.js CHANGED
@@ -28,14 +28,15 @@ const cspell = __importStar(require("cspell-lib"));
28
28
  const path = __importStar(require("path"));
29
29
  const util_1 = require("util");
30
30
  const vscode_uri_1 = require("vscode-uri");
31
- const fileHelper_1 = require("../util/fileHelper");
31
+ const cspell_pipe_1 = require("@cspell/cspell-pipe");
32
32
  const cache_1 = require("../util/cache");
33
33
  const errors_1 = require("../util/errors");
34
+ const fileHelper_1 = require("../util/fileHelper");
34
35
  const glob_1 = require("../util/glob");
35
36
  const reporters_1 = require("../util/reporters");
36
37
  const timer_1 = require("../util/timer");
37
38
  const util = __importStar(require("../util/util"));
38
- const async_1 = require("../util/async");
39
+ const chalk = require("chalk");
39
40
  async function runLint(cfg) {
40
41
  let { reporter } = cfg;
41
42
  cspell.setLogger(getLoggerFromReporter(reporter));
@@ -200,6 +201,7 @@ async function runLint(cfg) {
200
201
  return runResult();
201
202
  }
202
203
  header(fileGlobs, excludeGlobs);
204
+ checkGlobs(cfg.fileGlobs, reporter);
203
205
  reporter.info(`Config Files Found:\n ${configInfo.source}\n`, cspell_types_1.MessageTypes.Info);
204
206
  const configErrors = await countConfigErrors(configInfo);
205
207
  if (configErrors)
@@ -233,6 +235,12 @@ Options:
233
235
  }
234
236
  }
235
237
  exports.runLint = runLint;
238
+ function checkGlobs(globs, reporter) {
239
+ globs
240
+ .filter((g) => g.startsWith("'") || g.endsWith("'"))
241
+ .map((glob) => chalk.yellow(glob))
242
+ .forEach((glob) => reporter.error('Linter', new errors_1.CheckFailed(`Glob starting or ending with ' (single quote) is not likely to match any files: ${glob}.`)));
243
+ }
236
244
  async function determineGlobs(configInfo, cfg) {
237
245
  var _a, _b, _c;
238
246
  const useGitignore = (_b = (_a = cfg.options.gitignore) !== null && _a !== void 0 ? _a : configInfo.config.useGitignore) !== null && _b !== void 0 ? _b : false;
@@ -270,14 +278,14 @@ async function determineFilesToCheck(configInfo, cfg, reporter, globInfo) {
270
278
  if (enableGlobDot !== undefined) {
271
279
  globOptions.dot = enableGlobDot;
272
280
  }
273
- const filterFiles = (0, async_1.filter)(filterFilesFn(globMatcher));
281
+ const filterFiles = (0, cspell_pipe_1.opFilter)(filterFilesFn(globMatcher));
274
282
  const foundFiles = await (hasFileLists
275
283
  ? useFileLists(fileLists, allGlobs, root, enableGlobDot)
276
284
  : (0, fileHelper_1.findFiles)(fileGlobs, globOptions));
277
285
  const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles;
278
- const files = (0, async_1.isAsyncIterable)(filtered)
279
- ? (0, async_1.pipeAsync)(filtered, filterFiles)
280
- : [...(0, async_1.pipeSync)(filtered, filterFiles)];
286
+ const files = (0, cspell_pipe_1.isAsyncIterable)(filtered)
287
+ ? (0, cspell_pipe_1.pipeAsync)(filtered, filterFiles)
288
+ : [...(0, cspell_pipe_1.pipeSync)(filtered, filterFiles)];
281
289
  return files;
282
290
  }
283
291
  function isExcluded(filename, globMatcherExclude) {
@@ -384,6 +392,6 @@ async function useFileLists(fileListFiles, includeGlobPatterns, root, dot) {
384
392
  const globMatcher = new cspell_glob_1.GlobMatcher(includeGlobPatterns, options);
385
393
  const files = await (0, fileHelper_1.readFileListFiles)(fileListFiles);
386
394
  const filterFiles = (file) => globMatcher.match(file);
387
- return files instanceof Array ? files.filter(filterFiles) : (0, async_1.pipeAsync)(files, (0, async_1.filter)(filterFiles));
395
+ return files instanceof Array ? files.filter(filterFiles) : (0, cspell_pipe_1.pipeAsync)(files, (0, cspell_pipe_1.opFilter)(filterFiles));
388
396
  }
389
397
  //# sourceMappingURL=lint.js.map
@@ -1,46 +1,2 @@
1
- export declare const map: <T, U>(fn: (v: T) => U) => PipeFn<T, U>;
2
- export declare function asyncAwait<T>(): (iter: AsyncIterable<T>) => AsyncIterable<Awaited<T>>;
3
- export declare const filter: <T>(fn: (i: T) => boolean) => PipeFn<T, T>;
4
- interface PipeFnSync<T, U> {
5
- (iter: Iterable<T>): Iterable<U>;
6
- /** This is just to help TypeScript figure out the type. */
7
- __PipeFnSync__?: [T, U];
8
- }
9
- interface PipeFnAsync<T, U> {
10
- (iter: AsyncIterable<T>): AsyncIterable<U>;
11
- /** This is just to help TypeScript figure out the type. */
12
- __PipeFnAsync__?: [T, U];
13
- }
14
- declare type PipeFn<T, U> = PipeFnSync<T, U> & PipeFnAsync<T, U>;
15
- export declare function pipeAsync<T>(i: AnyIterable<T>): AsyncIterable<T>;
16
- export declare function pipeAsync<T, T0>(i: AnyIterable<T>, ...f: PipeAsyncTx<[T, T0]>): AsyncIterable<T0>;
17
- export declare function pipeAsync<T, T0, T1>(i: AnyIterable<T>, ...f: PipeAsyncTx<[T, T0, T1]>): AsyncIterable<T1>;
18
- export declare function pipeAsync<T, T0, T1, T2>(i: AnyIterable<T>, ...f: PipeAsyncTx<[T, T0, T1, T2]>): AsyncIterable<T2>;
19
- export declare function pipeAsync<T, T0, T1, T2, T3>(i: AnyIterable<T>, ...f: PipeAsyncTx<[T, T0, T1, T2, T3]>): AsyncIterable<T3>;
20
- export declare function pipeAsync<T, T0, T1, T2, T3, T4>(i: AnyIterable<T>, ...f: PipeAsyncTx<[T, T0, T1, T2, T3, T4]>): AsyncIterable<T4>;
21
- export declare function pipeAsync<T, T0, T1, T2, T3, T4, T5>(i: AnyIterable<T>, ...f: PipeAsyncTx<[T, T0, T1, T2, T3, T4, T5]>): AsyncIterable<T5>;
22
- declare type PsFn<T, U> = PipeFnSync<T, U> | ((i: Iterable<T>) => Iterable<U>);
23
- export declare function pipeSync<T>(i: Iterable<T>): Iterable<T>;
24
- export declare function pipeSync<T, T0 = T>(i: Iterable<T>, ...f: PipeSyncTx<[T, T0]>): Iterable<T0>;
25
- export declare function pipeSync<T, T0, T1>(i: Iterable<T>, ...f: PipeSyncTx<[T, T0, T1]>): Iterable<T1>;
26
- export declare function pipeSync<T, T0, T1, T2>(i: Iterable<T>, ...f: PipeSyncTx<[T, T0, T1, T2]>): Iterable<T2>;
27
- export declare function pipeSync<T, T0, T1, T2, T3>(i: Iterable<T>, ...f: PipeSyncTx<[T, T0, T1, T2, T3]>): Iterable<T3>;
28
- export declare function pipeSync<T, T0, T1, T2, T3, T4>(i: Iterable<T>, ...f: PipeSyncTx<[T, T0, T1, T2, T3, T4]>): Iterable<T4>;
29
- export declare function pipeSync<T, T0, T1, T2, T3, T4, T5>(i: Iterable<T>, ...f: PipeSyncTx<[T, T0, T1, T2, T3, T4, T5]>): Iterable<T5>;
30
- declare type AnyIterable<T> = Iterable<T> | AsyncIterable<T> | Promise<Iterable<T>> | Iterable<Promise<T>>;
31
- export declare function mergeAsyncIterables<T>(iter: Iterable<T>): AsyncIterable<T>;
32
- export declare function mergeAsyncIterables<T>(iter: AsyncIterable<T>): AsyncIterable<T>;
33
- export declare function mergeAsyncIterables<T>(iter: Promise<Iterable<T>>): AsyncIterable<T>;
34
- export declare function mergeAsyncIterables<T>(iter: AnyIterable<T>): AsyncIterable<T>;
35
- export declare function mergeAsyncIterables<T>(iter: AnyIterable<T>, ...rest: AnyIterable<T>[]): AsyncIterable<T>;
36
- /**
37
- * Convert one or more iterables to an AsyncIterable
38
- */
39
- export declare const toAsyncIterable: typeof mergeAsyncIterables;
40
- export declare function asyncIterableToArray<T>(iter: Iterable<T> | AsyncIterable<T>): Promise<Awaited<T>[]>;
41
- export declare function isAsyncIterable<T>(i: AnyIterable<T>): i is AsyncIterable<T>;
42
- declare type PaFn<T, U> = PipeFnAsync<T, U> | ((i: AsyncIterable<T>) => AsyncIterable<U>);
43
- declare type PipeAsyncTx<T extends [...any]> = T extends [infer Left, infer Right, ...infer Rest] ? Rest extends [any, ...any] ? [PaFn<Left, Right>, ...PipeAsyncTx<[Right, ...Rest]>] : [PaFn<Left, Right>] : never;
44
- declare type PipeSyncTx<T extends [...any]> = T extends [infer Left, infer Right, ...infer Rest] ? Rest extends [any, ...any] ? [PsFn<Left, Right>, ...PipeSyncTx<[Right, ...Rest]>] : [PsFn<Left, Right>] : never;
45
- export {};
1
+ export { toAsyncIterable as mergeAsyncIterables, toArray as asyncIterableToArray } from '@cspell/cspell-pipe';
46
2
  //# sourceMappingURL=async.d.ts.map
@@ -1,101 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAsyncIterable = exports.asyncIterableToArray = exports.toAsyncIterable = exports.mergeAsyncIterables = exports.pipeSync = exports.pipeAsync = exports.filter = exports.asyncAwait = exports.map = void 0;
4
- function asyncMap(mapFn) {
5
- async function* fn(iter) {
6
- for await (const v of iter) {
7
- yield mapFn(v);
8
- }
9
- }
10
- return fn;
11
- }
12
- function syncMap(mapFn) {
13
- function* fn(iter) {
14
- for (const v of iter) {
15
- yield mapFn(v);
16
- }
17
- }
18
- return fn;
19
- }
20
- const map = (fn) => toPipeFn(syncMap(fn), asyncMap(fn));
21
- exports.map = map;
22
- function asyncFilter(filterFn) {
23
- async function* fn(iter) {
24
- for await (const v of iter) {
25
- if (filterFn(v))
26
- yield v;
27
- }
28
- }
29
- return fn;
30
- }
31
- function syncFilter(filterFn) {
32
- function* fn(iter) {
33
- for (const v of iter) {
34
- if (filterFn(v))
35
- yield v;
36
- }
37
- }
38
- return fn;
39
- }
40
- async function* _asyncAwait(iter) {
41
- for await (const v of iter) {
42
- yield v;
43
- }
44
- }
45
- function asyncAwait() {
46
- return _asyncAwait;
47
- }
48
- exports.asyncAwait = asyncAwait;
49
- const filter = (fn) => toPipeFn(syncFilter(fn), asyncFilter(fn));
50
- exports.filter = filter;
51
- function toPipeFn(syncFn, asyncFn) {
52
- function _(i) {
53
- return isAsyncIterable(i) ? asyncFn(i) : syncFn(i);
54
- }
55
- return _;
56
- }
57
- function pipeAsync(i, ...fns) {
58
- let iter = (0, exports.toAsyncIterable)(i);
59
- for (const fn of fns) {
60
- iter = fn(iter);
61
- }
62
- return iter;
63
- }
64
- exports.pipeAsync = pipeAsync;
65
- function pipeSync(i, ...fns) {
66
- let iter = i;
67
- for (const fn of fns) {
68
- iter = fn(iter);
69
- }
70
- return iter;
71
- }
72
- exports.pipeSync = pipeSync;
73
- /**
74
- * Merge multiple iterables into an AsyncIterable
75
- * @param iter - initial iterable.
76
- * @param rest - iterables to merge.
77
- */
78
- async function* mergeAsyncIterables(iter, ...rest) {
79
- for await (const i of [iter, ...rest]) {
80
- yield* i;
81
- }
82
- }
83
- exports.mergeAsyncIterables = mergeAsyncIterables;
84
- /**
85
- * Convert one or more iterables to an AsyncIterable
86
- */
87
- exports.toAsyncIterable = mergeAsyncIterables;
88
- async function asyncIterableToArray(iter) {
89
- const r = [];
90
- for await (const t of iter) {
91
- r.push(t);
92
- }
93
- return r;
94
- }
95
- exports.asyncIterableToArray = asyncIterableToArray;
96
- function isAsyncIterable(i) {
97
- return typeof i[Symbol.asyncIterator] === 'function';
98
- }
99
- exports.isAsyncIterable = isAsyncIterable;
100
- // type Last<T extends [...any]> = T extends [infer U, ...infer R] ? (R extends [any, ...any] ? Last<R> : U) : never;
3
+ exports.asyncIterableToArray = exports.mergeAsyncIterables = void 0;
4
+ var cspell_pipe_1 = require("@cspell/cspell-pipe");
5
+ Object.defineProperty(exports, "mergeAsyncIterables", { enumerable: true, get: function () { return cspell_pipe_1.toAsyncIterable; } });
6
+ Object.defineProperty(exports, "asyncIterableToArray", { enumerable: true, get: function () { return cspell_pipe_1.toArray; } });
101
7
  //# sourceMappingURL=async.js.map
@@ -4,7 +4,9 @@ export declare function uniqueFilterFnGenerator<T>(): FilterFn<T>;
4
4
  export declare function uniqueFilterFnGenerator<T, U>(extractFn: (v: T) => U): FilterFn<T>;
5
5
  export declare function unique<T>(src: T[]): T[];
6
6
  export declare function clean<T>(src: T): T;
7
+ export declare function padWidth(s: string, target: number): number;
7
8
  export declare function pad(s: string, w: number): string;
8
9
  export declare function padLeft(s: string, w: number): string;
10
+ export declare function width(s: string): number;
9
11
  export {};
10
12
  //# sourceMappingURL=util.d.ts.map
package/dist/util/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.padLeft = exports.pad = exports.clean = exports.unique = exports.uniqueFilterFnGenerator = exports.uniqueFn = void 0;
3
+ exports.width = exports.padLeft = exports.pad = exports.padWidth = exports.clean = exports.unique = exports.uniqueFilterFnGenerator = exports.uniqueFn = void 0;
4
4
  // alias for uniqueFilterFnGenerator
5
5
  exports.uniqueFn = uniqueFilterFnGenerator;
6
6
  function uniqueFilterFnGenerator(extractFn) {
@@ -28,16 +28,28 @@ function clean(src) {
28
28
  return r;
29
29
  }
30
30
  exports.clean = clean;
31
+ function padWidth(s, target) {
32
+ const sWidth = width(s);
33
+ return Math.max(target - sWidth, 0);
34
+ }
35
+ exports.padWidth = padWidth;
31
36
  function pad(s, w) {
32
- if (s.length >= w)
37
+ const p = padWidth(s, w);
38
+ if (!p)
33
39
  return s;
34
- return (s + ' '.repeat(w)).slice(0, w);
40
+ return s + ' '.repeat(p);
35
41
  }
36
42
  exports.pad = pad;
37
43
  function padLeft(s, w) {
38
- if (s.length >= w)
44
+ const p = padWidth(s, w);
45
+ if (!p)
39
46
  return s;
40
- return (' '.repeat(w) + s).slice(-w);
47
+ return ' '.repeat(p) + s;
41
48
  }
42
49
  exports.padLeft = padLeft;
50
+ function width(s) {
51
+ // eslint-disable-next-line no-control-regex
52
+ return s.replace(/[\u0300-\u036f\x00-\x1f]/g, '').length;
53
+ }
54
+ exports.width = width;
43
55
  //# sourceMappingURL=util.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell",
3
- "version": "5.17.0",
3
+ "version": "5.18.2",
4
4
  "description": "A Spelling Checker for Code!",
5
5
  "funding": "https://github.com/streetsidesoftware/cspell?sponsor=1",
6
6
  "main": "dist/index.js",
@@ -70,12 +70,13 @@
70
70
  },
71
71
  "homepage": "https://streetsidesoftware.github.io/cspell/",
72
72
  "dependencies": {
73
+ "@cspell/cspell-pipe": "^5.18.2",
73
74
  "chalk": "^4.1.2",
74
- "commander": "^8.3.0",
75
+ "commander": "^9.0.0",
75
76
  "comment-json": "^4.1.1",
76
- "cspell-gitignore": "^5.17.0",
77
- "cspell-glob": "^5.17.0",
78
- "cspell-lib": "^5.17.0",
77
+ "cspell-gitignore": "^5.18.2",
78
+ "cspell-glob": "^5.18.2",
79
+ "cspell-lib": "^5.18.2",
79
80
  "fast-json-stable-stringify": "^2.1.0",
80
81
  "file-entry-cache": "^6.0.1",
81
82
  "fs-extra": "^10.0.0",
@@ -90,8 +91,8 @@
90
91
  "node": ">=12.13.0"
91
92
  },
92
93
  "devDependencies": {
93
- "@cspell/cspell-json-reporter": "^5.17.0",
94
- "@cspell/cspell-types": "^5.17.0",
94
+ "@cspell/cspell-json-reporter": "^5.18.2",
95
+ "@cspell/cspell-types": "^5.18.2",
95
96
  "@types/file-entry-cache": "^5.0.2",
96
97
  "@types/fs-extra": "^9.0.13",
97
98
  "@types/glob": "^7.2.0",
@@ -103,8 +104,8 @@
103
104
  "micromatch": "^4.0.4",
104
105
  "minimatch": "^3.0.4",
105
106
  "rimraf": "^3.0.2",
106
- "rollup": "^2.66.1",
107
+ "rollup": "^2.67.0",
107
108
  "rollup-plugin-dts": "^4.1.0"
108
109
  },
109
- "gitHead": "4e02d88a7add382088eb16d9b200e4bf07434f8f"
110
+ "gitHead": "baa92d5154ccf0a3a27d00ed169dd79cc80ea6cc"
110
111
  }