cspell 5.16.0 → 5.17.0-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.
- package/README.md +5 -1
- package/dist/app.js +2 -0
- package/dist/application.d.ts +5 -3
- package/dist/application.js +28 -7
- package/dist/commandLink.js +1 -1
- package/dist/commandLint.js +2 -0
- package/dist/commandSuggestion.d.ts +3 -0
- package/dist/commandSuggestion.js +83 -0
- package/dist/commandTrace.js +14 -12
- package/dist/emitters/suggestionsEmitter.d.ts +10 -0
- package/dist/emitters/suggestionsEmitter.js +42 -0
- package/dist/{traceEmitter.d.ts → emitters/traceEmitter.d.ts} +1 -1
- package/dist/{traceEmitter.js → emitters/traceEmitter.js} +9 -11
- package/dist/lint/LintRequest.js +1 -1
- package/dist/lint/lint.js +78 -51
- package/dist/options.d.ts +40 -4
- package/dist/options.js +9 -0
- package/dist/util/async.d.ts +46 -0
- package/dist/util/async.js +101 -0
- package/dist/util/cache/CSpellLintResultCache.d.ts +1 -1
- package/dist/util/cache/DiskCache.d.ts +1 -1
- package/dist/util/cache/DiskCache.js +1 -1
- package/dist/util/cache/getConfigHash.d.ts +1 -1
- package/dist/{fileHelper.d.ts → util/fileHelper.d.ts} +2 -2
- package/dist/{fileHelper.js → util/fileHelper.js} +13 -3
- package/dist/util/stdin.d.ts +2 -0
- package/dist/util/stdin.js +28 -0
- package/dist/util/util.d.ts +2 -0
- package/dist/util/util.js +13 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -11,6 +11,9 @@ A Spell Checker for Code!
|
|
|
11
11
|
## Support Future Development
|
|
12
12
|
|
|
13
13
|
- Become a [<img src="https://github.githubassets.com/images/modules/site/icons/funding_platforms/patreon.svg" width="16" height="16" alt="Patreon">Patreon!](https://patreon.com/streetsidesoftware)
|
|
14
|
+
- [Support through ](https://www.paypal.com/donate/?hosted_button_id=26LNBP2Q6MKCY)
|
|
15
|
+
- [Open Collective](https://opencollective.com/cspell)
|
|
16
|
+
- [Street Side Software](https://streetsidesoftware.com/support)
|
|
14
17
|
|
|
15
18
|
## Features
|
|
16
19
|
|
|
@@ -110,6 +113,7 @@ Options:
|
|
|
110
113
|
--no-progress Turn off progress messages
|
|
111
114
|
--no-summary Turn off summary message in console.
|
|
112
115
|
-s, --silent Silent mode, suppress error messages.
|
|
116
|
+
--fail-fast Exit after first file with an issue or error.
|
|
113
117
|
-r, --root <root folder> Root directory, defaults to current directory.
|
|
114
118
|
--relative Issues are displayed relative to root.
|
|
115
119
|
--show-context Show the surrounding text around an issue.
|
|
@@ -206,7 +210,7 @@ npm install -SD cspell
|
|
|
206
210
|
```
|
|
207
211
|
#!/bin/sh
|
|
208
212
|
|
|
209
|
-
exec git diff --cached --name-only | npx cspell --
|
|
213
|
+
exec git diff --cached --name-only | npx cspell --no-summary --no-progress --no-must-find-files --file-list stdin
|
|
210
214
|
```
|
|
211
215
|
|
|
212
216
|
## Requirements
|
package/dist/app.js
CHANGED
|
@@ -27,6 +27,7 @@ const commandCheck_1 = require("./commandCheck");
|
|
|
27
27
|
const commandLink_1 = require("./commandLink");
|
|
28
28
|
const commandLint_1 = require("./commandLint");
|
|
29
29
|
const commandTrace_1 = require("./commandTrace");
|
|
30
|
+
const commandSuggestion_1 = require("./commandSuggestion");
|
|
30
31
|
const errors_1 = require("./util/errors");
|
|
31
32
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
32
33
|
const npmPackage = require(path.join(__dirname, '..', 'package.json'));
|
|
@@ -44,6 +45,7 @@ async function run(program, argv) {
|
|
|
44
45
|
(0, commandTrace_1.commandTrace)(prog);
|
|
45
46
|
(0, commandCheck_1.commandCheck)(prog);
|
|
46
47
|
(0, commandLink_1.commandLink)(prog);
|
|
48
|
+
(0, commandSuggestion_1.commandSuggestion)(prog);
|
|
47
49
|
/*
|
|
48
50
|
program
|
|
49
51
|
.command('init')
|
package/dist/application.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { CSpellReporter, RunResult } from '@cspell/cspell-types';
|
|
3
|
+
import * as cspell from 'cspell-lib';
|
|
3
4
|
import { CheckTextInfo, TraceResult } from 'cspell-lib';
|
|
4
|
-
import { BaseOptions, LinterOptions, TraceOptions } from './options';
|
|
5
|
+
import { BaseOptions, LegacyOptions, LinterOptions, SuggestionOptions, TraceOptions } from './options';
|
|
5
6
|
export { IncludeExcludeFlag } from 'cspell-lib';
|
|
6
7
|
export type { TraceResult } from 'cspell-lib';
|
|
7
8
|
export declare type AppError = NodeJS.ErrnoException;
|
|
8
9
|
export declare function lint(fileGlobs: string[], options: LinterOptions, emitters: CSpellReporter): Promise<RunResult>;
|
|
9
|
-
export declare function trace(words: string[], options: TraceOptions):
|
|
10
|
+
export declare function trace(words: string[], options: TraceOptions): AsyncIterableIterator<TraceResult[]>;
|
|
10
11
|
export declare type CheckTextResult = CheckTextInfo;
|
|
11
|
-
export declare function checkText(filename: string, options: BaseOptions): Promise<CheckTextResult>;
|
|
12
|
+
export declare function checkText(filename: string, options: BaseOptions & LegacyOptions): Promise<CheckTextResult>;
|
|
13
|
+
export declare function suggestions(words: string[], options: SuggestionOptions): AsyncIterable<cspell.SuggestionsForWordResult>;
|
|
12
14
|
export declare function createInit(): Promise<void>;
|
|
13
15
|
//# sourceMappingURL=application.d.ts.map
|
package/dist/application.js
CHANGED
|
@@ -19,30 +19,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.createInit = exports.checkText = exports.trace = exports.lint = exports.IncludeExcludeFlag = void 0;
|
|
22
|
+
exports.createInit = exports.suggestions = exports.checkText = exports.trace = exports.lint = exports.IncludeExcludeFlag = void 0;
|
|
23
23
|
const cspell = __importStar(require("cspell-lib"));
|
|
24
24
|
const cspell_lib_1 = require("cspell-lib");
|
|
25
25
|
const path = __importStar(require("path"));
|
|
26
|
-
const fileHelper_1 = require("./fileHelper");
|
|
26
|
+
const fileHelper_1 = require("./util/fileHelper");
|
|
27
27
|
const lint_1 = require("./lint");
|
|
28
|
+
const options_1 = require("./options");
|
|
29
|
+
const stdin_1 = require("./util/stdin");
|
|
28
30
|
const util = __importStar(require("./util/util"));
|
|
31
|
+
const async = __importStar(require("./util/async"));
|
|
29
32
|
var cspell_lib_2 = require("cspell-lib");
|
|
30
33
|
Object.defineProperty(exports, "IncludeExcludeFlag", { enumerable: true, get: function () { return cspell_lib_2.IncludeExcludeFlag; } });
|
|
31
34
|
function lint(fileGlobs, options, emitters) {
|
|
35
|
+
options = (0, options_1.fixLegacy)(options);
|
|
32
36
|
const cfg = new lint_1.LintRequest(fileGlobs, options, emitters);
|
|
33
37
|
return (0, lint_1.runLint)(cfg);
|
|
34
38
|
}
|
|
35
39
|
exports.lint = lint;
|
|
36
|
-
async function trace(words, options) {
|
|
37
|
-
|
|
38
|
-
const
|
|
40
|
+
async function* trace(words, options) {
|
|
41
|
+
options = (0, options_1.fixLegacy)(options);
|
|
42
|
+
const iWords = options.stdin ? async.mergeAsyncIterables(words, (0, stdin_1.readStdin)()) : words;
|
|
43
|
+
const { languageId, locale, allowCompoundWords, ignoreCase } = options;
|
|
39
44
|
const configFile = await (0, fileHelper_1.readConfig)(options.config, undefined);
|
|
40
45
|
const config = cspell.mergeSettings(cspell.getDefaultSettings(), cspell.getGlobalSettings(), configFile.config);
|
|
41
|
-
|
|
42
|
-
return results;
|
|
46
|
+
yield* (0, cspell_lib_1.traceWordsAsync)(iWords, config, { languageId, locale, ignoreCase, allowCompoundWords });
|
|
43
47
|
}
|
|
44
48
|
exports.trace = trace;
|
|
45
49
|
async function checkText(filename, options) {
|
|
50
|
+
options = (0, options_1.fixLegacy)(options);
|
|
46
51
|
const pSettings = (0, fileHelper_1.readConfig)(options.config, path.dirname(filename));
|
|
47
52
|
const [foundSettings, text] = await Promise.all([pSettings, (0, fileHelper_1.readFile)(filename)]);
|
|
48
53
|
const settingsFromCommandLine = util.clean({
|
|
@@ -53,6 +58,22 @@ async function checkText(filename, options) {
|
|
|
53
58
|
return cspell.checkText(text, info.configInfo.config);
|
|
54
59
|
}
|
|
55
60
|
exports.checkText = checkText;
|
|
61
|
+
async function* suggestions(words, options) {
|
|
62
|
+
options = (0, options_1.fixLegacy)(options);
|
|
63
|
+
const configFile = await (0, fileHelper_1.readConfig)(options.config, undefined);
|
|
64
|
+
const iWords = options.useStdin ? async.mergeAsyncIterables(words, (0, stdin_1.readStdin)()) : words;
|
|
65
|
+
try {
|
|
66
|
+
const results = (0, cspell_lib_1.suggestionsForWords)(iWords, options, configFile.config);
|
|
67
|
+
yield* results;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
if (!(e instanceof cspell_lib_1.SuggestionError))
|
|
71
|
+
throw e;
|
|
72
|
+
console.error(e.message);
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.suggestions = suggestions;
|
|
56
77
|
function createInit() {
|
|
57
78
|
return Promise.reject();
|
|
58
79
|
}
|
package/dist/commandLink.js
CHANGED
|
@@ -7,7 +7,7 @@ const table_1 = require("./util/table");
|
|
|
7
7
|
function commandLink(prog) {
|
|
8
8
|
const linkCommand = prog
|
|
9
9
|
.command('link')
|
|
10
|
-
.description('Link dictionaries
|
|
10
|
+
.description('Link dictionaries and other settings to the cspell global config.');
|
|
11
11
|
linkCommand
|
|
12
12
|
.command('list', { isDefault: true })
|
|
13
13
|
.alias('ls')
|
package/dist/commandLint.js
CHANGED
|
@@ -62,6 +62,8 @@ function commandLint(prog) {
|
|
|
62
62
|
.option('--no-progress', 'Turn off progress messages')
|
|
63
63
|
.option('--no-summary', 'Turn off summary message in console.')
|
|
64
64
|
.option('-s, --silent', 'Silent mode, suppress error messages.')
|
|
65
|
+
.option('--fail-fast', 'Exit after first file with an issue or error.')
|
|
66
|
+
.addOption(new commander_1.Option('--no-fail-fast', 'Process all files even if there is an error.').hideHelp())
|
|
65
67
|
.option('-r, --root <root folder>', 'Root directory, defaults to current directory.')
|
|
66
68
|
.option('--relative', 'Issues are displayed relative to root.')
|
|
67
69
|
.option('--show-context', 'Show the surrounding text around an issue.')
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.commandSuggestion = void 0;
|
|
23
|
+
const commander_1 = require("commander");
|
|
24
|
+
const App = __importStar(require("./application"));
|
|
25
|
+
const suggestionsEmitter_1 = require("./emitters/suggestionsEmitter");
|
|
26
|
+
const errors_1 = require("./util/errors");
|
|
27
|
+
function collect(value, previous) {
|
|
28
|
+
value = value.replace(/^=/, '');
|
|
29
|
+
if (!previous) {
|
|
30
|
+
return [value];
|
|
31
|
+
}
|
|
32
|
+
return previous.concat([value]);
|
|
33
|
+
}
|
|
34
|
+
function count(_, previous) {
|
|
35
|
+
return (previous || 0) + 1;
|
|
36
|
+
}
|
|
37
|
+
function asNumber(value, prev) {
|
|
38
|
+
var _a;
|
|
39
|
+
return (_a = parseInt(value, 10)) !== null && _a !== void 0 ? _a : prev;
|
|
40
|
+
}
|
|
41
|
+
function commandSuggestion(prog) {
|
|
42
|
+
const suggestionCommand = prog.command('suggestions');
|
|
43
|
+
suggestionCommand
|
|
44
|
+
.aliases(['sug', 'suggest'])
|
|
45
|
+
.description('Spelling Suggestions for words.')
|
|
46
|
+
.option('-c, --config <cspell.json>', 'Configuration file to use. By default cspell looks for cspell.json in the current directory.')
|
|
47
|
+
.option('--locale <locale>', 'Set language locales. i.e. "en,fr" for English and French, or "en-GB" for British English.')
|
|
48
|
+
.option('--language-id <language>', 'Use programming language. i.e. "php" or "scala".')
|
|
49
|
+
.addOption(new commander_1.Option('--languageId <language>', 'Use programming language. i.e. "php" or "scala".').hideHelp())
|
|
50
|
+
.option('-s, --no-strict', 'Ignore case and accents when searching for words.')
|
|
51
|
+
.option('--ignore-case', 'Alias of --no-strict.')
|
|
52
|
+
.option('--num-changes <number>', 'Number of changes allowed to a word', asNumber, 4)
|
|
53
|
+
.option('--num-suggestions <number>', 'Number of suggestions', asNumber, 8)
|
|
54
|
+
.option('--no-include-ties', 'Force the number of suggested to be limited, by not including suggestions that have the same edit cost.')
|
|
55
|
+
.option('--stdin', 'Use stdin for input.')
|
|
56
|
+
.option('-v, --verbose', 'Show detailed output.', count, 0)
|
|
57
|
+
.option('-d, --dictionary <dictionary name>', 'Use the dictionary specified. Only dictionaries specified will be used.', collect)
|
|
58
|
+
.option('--dictionaries <dictionary names...>', 'Use the dictionaries specified. Only dictionaries specified will be used.')
|
|
59
|
+
.option('--no-color', 'Turn off color.')
|
|
60
|
+
.option('--color', 'Force color')
|
|
61
|
+
.arguments('[words...]')
|
|
62
|
+
.action(async (words, options) => {
|
|
63
|
+
options.useStdin = options.stdin;
|
|
64
|
+
options.dictionaries = mergeArrays(options.dictionaries, options.dictionary);
|
|
65
|
+
if (!words.length && !options.useStdin) {
|
|
66
|
+
suggestionCommand.outputHelp();
|
|
67
|
+
throw new errors_1.CheckFailed('outputHelp', 1);
|
|
68
|
+
}
|
|
69
|
+
for await (const r of App.suggestions(words, options)) {
|
|
70
|
+
(0, suggestionsEmitter_1.emitSuggestionResult)(r, options);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return suggestionCommand;
|
|
74
|
+
}
|
|
75
|
+
exports.commandSuggestion = commandSuggestion;
|
|
76
|
+
function mergeArrays(a, b) {
|
|
77
|
+
if (a === undefined)
|
|
78
|
+
return b;
|
|
79
|
+
if (b === undefined)
|
|
80
|
+
return a;
|
|
81
|
+
return a.concat(b);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=commandSuggestion.js.map
|
package/dist/commandTrace.js
CHANGED
|
@@ -22,13 +22,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.commandTrace = void 0;
|
|
23
23
|
const commander_1 = require("commander");
|
|
24
24
|
const App = __importStar(require("./application"));
|
|
25
|
-
const traceEmitter_1 = require("./traceEmitter");
|
|
25
|
+
const traceEmitter_1 = require("./emitters/traceEmitter");
|
|
26
26
|
const errors_1 = require("./util/errors");
|
|
27
27
|
function commandTrace(prog) {
|
|
28
28
|
return prog
|
|
29
29
|
.command('trace')
|
|
30
|
-
.description(`Trace words
|
|
31
|
-
Search for words in the configuration and dictionaries.`)
|
|
30
|
+
.description(`Trace words -- Search for words in the configuration and dictionaries.`)
|
|
32
31
|
.option('-c, --config <cspell.json>', 'Configuration file to use. By default cspell looks for cspell.json in the current directory.')
|
|
33
32
|
.option('--locale <locale>', 'Set language locales. i.e. "en,fr" for English and French, or "en-GB" for British English.')
|
|
34
33
|
.option('--language-id <language>', 'Use programming language. i.e. "php" or "scala"')
|
|
@@ -37,22 +36,25 @@ function commandTrace(prog) {
|
|
|
37
36
|
.addOption(new commander_1.Option('--allowCompoundWords', 'Turn on allowCompoundWords').hideHelp())
|
|
38
37
|
.option('--no-allow-compound-words', 'Turn off allowCompoundWords')
|
|
39
38
|
.option('--no-ignore-case', 'Do not ignore case and accents when searching for words')
|
|
39
|
+
.option('--stdin', 'Read words from stdin.')
|
|
40
40
|
.option('--no-color', 'Turn off color.')
|
|
41
41
|
.option('--color', 'Force color')
|
|
42
|
-
.arguments('
|
|
42
|
+
.arguments('[words...]')
|
|
43
43
|
.action(async (words, options) => {
|
|
44
|
-
|
|
45
|
-
(
|
|
46
|
-
|
|
44
|
+
let numFound = 0;
|
|
45
|
+
for await (const results of App.trace(words, options)) {
|
|
46
|
+
(0, traceEmitter_1.emitTraceResults)(results, { cwd: process.cwd() });
|
|
47
|
+
numFound += results.reduce((n, r) => n + (r.found ? 1 : 0), 0);
|
|
48
|
+
const numErrors = results.map((r) => { var _a; return ((_a = r.errors) === null || _a === void 0 ? void 0 : _a.length) || 0; }).reduce((n, r) => n + r, 0);
|
|
49
|
+
if (numErrors) {
|
|
50
|
+
console.error('Dictionary Errors.');
|
|
51
|
+
throw new errors_1.CheckFailed('dictionary errors', 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
47
54
|
if (!numFound) {
|
|
48
55
|
console.error('No matches found');
|
|
49
56
|
throw new errors_1.CheckFailed('no matches', 1);
|
|
50
57
|
}
|
|
51
|
-
const numErrors = results.map((r) => { var _a; return ((_a = r.errors) === null || _a === void 0 ? void 0 : _a.length) || 0; }).reduce((n, r) => n + r, 0);
|
|
52
|
-
if (numErrors) {
|
|
53
|
-
console.error('Dictionary Errors.');
|
|
54
|
-
throw new errors_1.CheckFailed('dictionary errors', 1);
|
|
55
|
-
}
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
exports.commandTrace = commandTrace;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SuggestionsForWordResult } from 'cspell-lib';
|
|
2
|
+
export interface EmitSuggestionOptions {
|
|
3
|
+
verbose?: number;
|
|
4
|
+
lineWidth?: number;
|
|
5
|
+
output?: {
|
|
6
|
+
log: (text: string) => void;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function emitSuggestionResult(result: SuggestionsForWordResult, options: EmitSuggestionOptions): void;
|
|
10
|
+
//# sourceMappingURL=suggestionsEmitter.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitSuggestionResult = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const util_1 = require("../util/util");
|
|
6
|
+
function emitSuggestionResult(result, options) {
|
|
7
|
+
const { word, suggestions } = result;
|
|
8
|
+
const { verbose, output = console } = options;
|
|
9
|
+
output.log(word ? chalk.green(word) : chalk.yellow('<empty>') + ':');
|
|
10
|
+
if (!suggestions.length) {
|
|
11
|
+
console.log(chalk.yellow(' <no suggestions>'));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (verbose) {
|
|
15
|
+
const maxWidth = suggestions.map((r) => r.word.length).reduce((max, len) => Math.max(max, len), 0);
|
|
16
|
+
for (const sug of suggestions) {
|
|
17
|
+
const { word, cost, dictionaries } = sug;
|
|
18
|
+
const padding = ' '.repeat(maxWidth - word.length);
|
|
19
|
+
const forbid = sug.forbidden ? chalk.red('X') : ' ';
|
|
20
|
+
const ignore = sug.noSuggest ? chalk.yellow('N') : ' ';
|
|
21
|
+
const strCost = (0, util_1.padLeft)(cost.toString(10), 4);
|
|
22
|
+
const dicts = dictionaries.map((n) => chalk.gray(n)).join(', ');
|
|
23
|
+
output.log(` - ${formatWord(word, sug)}${padding} ${forbid}${ignore} - ${chalk.yellow(strCost)} ${dicts}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
for (const r of suggestions) {
|
|
28
|
+
output.log(` - ${formatWordSingle(r)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.emitSuggestionResult = emitSuggestionResult;
|
|
33
|
+
function formatWord(word, r) {
|
|
34
|
+
return r.forbidden || r.noSuggest ? chalk.gray(chalk.strikethrough(word)) : word;
|
|
35
|
+
}
|
|
36
|
+
function formatWordSingle(s) {
|
|
37
|
+
let word = formatWord(s.word, s);
|
|
38
|
+
word = s.forbidden ? word + chalk.red(' X') : word;
|
|
39
|
+
word = s.noSuggest ? word + chalk.yellow(' Not suggested.') : word;
|
|
40
|
+
return word;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=suggestionsEmitter.js.map
|
|
@@ -23,9 +23,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.emitTraceResults = void 0;
|
|
26
|
-
const chalk = require("chalk");
|
|
27
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
28
26
|
const Path = __importStar(require("path"));
|
|
27
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
28
|
+
const util_1 = require("../util/util");
|
|
29
|
+
const chalk = require("chalk");
|
|
29
30
|
const colWidthDictionaryName = 20;
|
|
30
31
|
function emitTraceResults(results, options) {
|
|
31
32
|
var _a;
|
|
@@ -45,10 +46,10 @@ function emitTraceResults(results, options) {
|
|
|
45
46
|
exports.emitTraceResults = emitTraceResults;
|
|
46
47
|
function emitHeader(colWidths) {
|
|
47
48
|
const line = [
|
|
48
|
-
pad('Word', colWidths.word),
|
|
49
|
+
(0, util_1.pad)('Word', colWidths.word),
|
|
49
50
|
'F',
|
|
50
|
-
pad('Dictionary', colWidths.dictName),
|
|
51
|
-
pad('Dictionary Location', 30),
|
|
51
|
+
(0, util_1.pad)('Dictionary', colWidths.dictName),
|
|
52
|
+
(0, util_1.pad)('Dictionary Location', 30),
|
|
52
53
|
];
|
|
53
54
|
console.log(chalk.underline(line.join(' ').slice(0, colWidths.terminalWidth)));
|
|
54
55
|
}
|
|
@@ -56,12 +57,12 @@ function emitTraceResult(r, colWidths, options) {
|
|
|
56
57
|
var _a, _b;
|
|
57
58
|
const { word: wordColWidth, terminalWidth, dictName: widthName } = colWidths;
|
|
58
59
|
const errors = ((_b = (_a = r.errors) === null || _a === void 0 ? void 0 : _a.map((e) => e.message)) === null || _b === void 0 ? void 0 : _b.join('\n\t')) || '';
|
|
59
|
-
const word = pad(r.foundWord || r.word, wordColWidth);
|
|
60
|
+
const word = (0, util_1.pad)(r.foundWord || r.word, wordColWidth);
|
|
60
61
|
const cWord = word.replace(/[+]/g, chalk.yellow('+'));
|
|
61
62
|
const w = r.forbidden ? chalk.red(cWord) : chalk.green(cWord);
|
|
62
63
|
const f = calcFoundChar(r);
|
|
63
64
|
const a = r.dictActive ? '*' : ' ';
|
|
64
|
-
const dictName = pad(r.dictName.slice(0, widthName - 1) + a, widthName);
|
|
65
|
+
const dictName = (0, util_1.pad)(r.dictName.slice(0, widthName - 1) + a, widthName);
|
|
65
66
|
const dictColor = r.dictActive ? chalk.yellowBright : chalk.rgb(200, 128, 50);
|
|
66
67
|
const n = dictColor(dictName);
|
|
67
68
|
const info = [w, f, n].join(' ') + ' ';
|
|
@@ -75,9 +76,6 @@ function emitTraceResult(r, colWidths, options) {
|
|
|
75
76
|
console.error('\t' + chalk.red(errors));
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
|
-
function pad(s, w) {
|
|
79
|
-
return (s + ' '.repeat(w)).substr(0, w);
|
|
80
|
-
}
|
|
81
79
|
function trimMid(s, w) {
|
|
82
80
|
s = s.trim();
|
|
83
81
|
if (s.length <= w) {
|
|
@@ -85,7 +83,7 @@ function trimMid(s, w) {
|
|
|
85
83
|
}
|
|
86
84
|
const l = Math.floor((w - 3) / 2);
|
|
87
85
|
const r = Math.ceil((w - 3) / 2);
|
|
88
|
-
return s.
|
|
86
|
+
return s.slice(0, l) + '...' + s.slice(-r);
|
|
89
87
|
}
|
|
90
88
|
function calcFoundChar(r) {
|
|
91
89
|
var _a, _b;
|
package/dist/lint/LintRequest.js
CHANGED
|
@@ -32,7 +32,7 @@ class LintRequest {
|
|
|
32
32
|
this.root = path.resolve(options.root || process.cwd());
|
|
33
33
|
this.configFile = options.config;
|
|
34
34
|
this.excludes = (0, glob_1.calcExcludeGlobInfo)(this.root, options.exclude);
|
|
35
|
-
this.locale = options.locale ||
|
|
35
|
+
this.locale = options.locale || '';
|
|
36
36
|
this.enableGlobDot = options.dot;
|
|
37
37
|
this.uniqueFilter = options.unique ? util.uniqueFilterFnGenerator((issue) => issue.text) : () => true;
|
|
38
38
|
this.showContext =
|
package/dist/lint/lint.js
CHANGED
|
@@ -28,16 +28,16 @@ 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("../fileHelper");
|
|
31
|
+
const fileHelper_1 = require("../util/fileHelper");
|
|
32
32
|
const cache_1 = require("../util/cache");
|
|
33
33
|
const errors_1 = require("../util/errors");
|
|
34
34
|
const glob_1 = require("../util/glob");
|
|
35
35
|
const reporters_1 = require("../util/reporters");
|
|
36
36
|
const timer_1 = require("../util/timer");
|
|
37
37
|
const util = __importStar(require("../util/util"));
|
|
38
|
+
const async_1 = require("../util/async");
|
|
38
39
|
async function runLint(cfg) {
|
|
39
40
|
let { reporter } = cfg;
|
|
40
|
-
const { fileLists } = cfg;
|
|
41
41
|
cspell.setLogger(getLoggerFromReporter(reporter));
|
|
42
42
|
const configErrors = new Set();
|
|
43
43
|
const lintResult = await run();
|
|
@@ -108,13 +108,15 @@ async function runLint(cfg) {
|
|
|
108
108
|
return { ...tdo, context };
|
|
109
109
|
}
|
|
110
110
|
async function processFiles(files, configInfo, cacheSettings) {
|
|
111
|
-
|
|
111
|
+
var _a, _b;
|
|
112
|
+
const fileCount = files instanceof Array ? files.length : undefined;
|
|
112
113
|
const status = runResult();
|
|
113
114
|
const cache = (0, cache_1.createCache)(cacheSettings);
|
|
115
|
+
const failFast = (_b = (_a = cfg.options.failFast) !== null && _a !== void 0 ? _a : configInfo.config.failFast) !== null && _b !== void 0 ? _b : false;
|
|
114
116
|
const emitProgress = (filename, fileNum, result) => reporter.progress({
|
|
115
117
|
type: 'ProgressFileComplete',
|
|
116
118
|
fileNum,
|
|
117
|
-
fileCount,
|
|
119
|
+
fileCount: fileCount !== null && fileCount !== void 0 ? fileCount : fileNum,
|
|
118
120
|
filename,
|
|
119
121
|
elapsedTimeMs: result === null || result === void 0 ? void 0 : result.elapsedTimeMs,
|
|
120
122
|
processed: result === null || result === void 0 ? void 0 : result.processed,
|
|
@@ -122,10 +124,11 @@ async function runLint(cfg) {
|
|
|
122
124
|
cached: result === null || result === void 0 ? void 0 : result.cached,
|
|
123
125
|
});
|
|
124
126
|
async function* loadAndProcessFiles() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
let i = 0;
|
|
128
|
+
for await (const filename of files) {
|
|
129
|
+
++i;
|
|
127
130
|
const result = await processFile(filename, configInfo, cache);
|
|
128
|
-
yield { filename, fileNum: i
|
|
131
|
+
yield { filename, fileNum: i, result };
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
for await (const fileP of loadAndProcessFiles()) {
|
|
@@ -139,6 +142,9 @@ async function runLint(cfg) {
|
|
|
139
142
|
status.filesWithIssues.add(filename);
|
|
140
143
|
status.issues += result.issues.length;
|
|
141
144
|
status.errors += result.errors;
|
|
145
|
+
if (failFast) {
|
|
146
|
+
return status;
|
|
147
|
+
}
|
|
142
148
|
}
|
|
143
149
|
status.errors += result.configErrors;
|
|
144
150
|
}
|
|
@@ -180,25 +186,15 @@ async function runLint(cfg) {
|
|
|
180
186
|
return reportConfigurationErrors(configInfo.config);
|
|
181
187
|
}
|
|
182
188
|
async function run() {
|
|
183
|
-
var _a, _b, _c, _d;
|
|
184
189
|
if (cfg.options.root) {
|
|
185
190
|
process.env[cspell.ENV_CSPELL_GLOB_ROOT] = cfg.root;
|
|
186
191
|
}
|
|
187
192
|
const configInfo = await (0, fileHelper_1.readConfig)(cfg.configFile, cfg.root);
|
|
188
193
|
reporter = (0, reporters_1.mergeReporters)(cfg.reporter, ...(0, reporters_1.loadReporters)(configInfo.config));
|
|
189
194
|
cspell.setLogger(getLoggerFromReporter(reporter));
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const cliGlobs = cfg.fileGlobs;
|
|
194
|
-
const allGlobs = cliGlobs.length ? cliGlobs : configInfo.config.files || [];
|
|
195
|
-
const combinedGlobs = (0, glob_1.normalizeGlobsToRoot)(allGlobs, cfg.root, false);
|
|
196
|
-
const cliExcludeGlobs = (0, glob_1.extractPatterns)(cfg.excludes).map((p) => p.glob);
|
|
197
|
-
const normalizedExcludes = (0, glob_1.normalizeGlobsToRoot)(cliExcludeGlobs, cfg.root, true);
|
|
198
|
-
const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
|
|
199
|
-
const excludeGlobs = combinedGlobs.filter((g) => g.startsWith('!')).concat(normalizedExcludes);
|
|
200
|
-
const fileGlobs = includeGlobs;
|
|
201
|
-
const hasFileLists = !!fileLists.length;
|
|
195
|
+
const globInfo = await determineGlobs(configInfo, cfg);
|
|
196
|
+
const { fileGlobs, excludeGlobs } = globInfo;
|
|
197
|
+
const hasFileLists = !!cfg.fileLists.length;
|
|
202
198
|
if (!fileGlobs.length && !hasFileLists) {
|
|
203
199
|
// Nothing to do.
|
|
204
200
|
return runResult();
|
|
@@ -210,27 +206,9 @@ async function runLint(cfg) {
|
|
|
210
206
|
return runResult({ errors: configErrors });
|
|
211
207
|
// Get Exclusions from the config files.
|
|
212
208
|
const { root } = cfg;
|
|
213
|
-
const globsToExclude = (configInfo.config.ignorePaths || []).concat(excludeGlobs);
|
|
214
|
-
const globMatcher = (0, glob_1.buildGlobMatcher)(globsToExclude, root, true);
|
|
215
|
-
const ignoreGlobs = (0, glob_1.extractGlobsFromMatcher)(globMatcher);
|
|
216
|
-
// cspell:word nodir
|
|
217
|
-
const globOptions = {
|
|
218
|
-
root,
|
|
219
|
-
cwd: root,
|
|
220
|
-
ignore: ignoreGlobs.concat(normalizedExcludes),
|
|
221
|
-
nodir: true,
|
|
222
|
-
};
|
|
223
|
-
const enableGlobDot = (_d = cfg.enableGlobDot) !== null && _d !== void 0 ? _d : configInfo.config.enableGlobDot;
|
|
224
|
-
if (enableGlobDot !== undefined) {
|
|
225
|
-
globOptions.dot = enableGlobDot;
|
|
226
|
-
}
|
|
227
209
|
try {
|
|
228
210
|
const cacheSettings = await (0, cache_1.calcCacheSettings)(configInfo.config, cfg.options, root);
|
|
229
|
-
const
|
|
230
|
-
? useFileLists(fileLists, allGlobs, root, enableGlobDot)
|
|
231
|
-
: (0, fileHelper_1.findFiles)(fileGlobs, globOptions));
|
|
232
|
-
const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles;
|
|
233
|
-
const files = filterFiles(filtered, globMatcher);
|
|
211
|
+
const files = await determineFilesToCheck(configInfo, cfg, reporter, globInfo);
|
|
234
212
|
return await processFiles(files, configInfo, cacheSettings);
|
|
235
213
|
}
|
|
236
214
|
catch (e) {
|
|
@@ -253,6 +231,55 @@ Options:
|
|
|
253
231
|
unique: ${yesNo(!!cfg.options.unique)}
|
|
254
232
|
`, cspell_types_1.MessageTypes.Info);
|
|
255
233
|
}
|
|
234
|
+
}
|
|
235
|
+
exports.runLint = runLint;
|
|
236
|
+
async function determineGlobs(configInfo, cfg) {
|
|
237
|
+
var _a, _b, _c;
|
|
238
|
+
const useGitignore = (_b = (_a = cfg.options.gitignore) !== null && _a !== void 0 ? _a : configInfo.config.useGitignore) !== null && _b !== void 0 ? _b : false;
|
|
239
|
+
const gitignoreRoots = (_c = cfg.options.gitignoreRoot) !== null && _c !== void 0 ? _c : configInfo.config.gitignoreRoot;
|
|
240
|
+
const gitIgnore = useGitignore ? await generateGitIgnore(gitignoreRoots) : undefined;
|
|
241
|
+
const cliGlobs = cfg.fileGlobs;
|
|
242
|
+
const allGlobs = cliGlobs.length ? cliGlobs : configInfo.config.files || [];
|
|
243
|
+
const combinedGlobs = (0, glob_1.normalizeGlobsToRoot)(allGlobs, cfg.root, false);
|
|
244
|
+
const cliExcludeGlobs = (0, glob_1.extractPatterns)(cfg.excludes).map((p) => p.glob);
|
|
245
|
+
const normalizedExcludes = (0, glob_1.normalizeGlobsToRoot)(cliExcludeGlobs, cfg.root, true);
|
|
246
|
+
const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
|
|
247
|
+
const excludeGlobs = combinedGlobs.filter((g) => g.startsWith('!')).concat(normalizedExcludes);
|
|
248
|
+
const fileGlobs = includeGlobs;
|
|
249
|
+
return { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes };
|
|
250
|
+
}
|
|
251
|
+
async function determineFilesToCheck(configInfo, cfg, reporter, globInfo) {
|
|
252
|
+
async function _determineFilesToCheck() {
|
|
253
|
+
var _a;
|
|
254
|
+
const { fileLists } = cfg;
|
|
255
|
+
const hasFileLists = !!fileLists.length;
|
|
256
|
+
const { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes } = globInfo;
|
|
257
|
+
// Get Exclusions from the config files.
|
|
258
|
+
const { root } = cfg;
|
|
259
|
+
const globsToExclude = (configInfo.config.ignorePaths || []).concat(excludeGlobs);
|
|
260
|
+
const globMatcher = (0, glob_1.buildGlobMatcher)(globsToExclude, root, true);
|
|
261
|
+
const ignoreGlobs = (0, glob_1.extractGlobsFromMatcher)(globMatcher);
|
|
262
|
+
// cspell:word nodir
|
|
263
|
+
const globOptions = {
|
|
264
|
+
root,
|
|
265
|
+
cwd: root,
|
|
266
|
+
ignore: ignoreGlobs.concat(normalizedExcludes),
|
|
267
|
+
nodir: true,
|
|
268
|
+
};
|
|
269
|
+
const enableGlobDot = (_a = cfg.enableGlobDot) !== null && _a !== void 0 ? _a : configInfo.config.enableGlobDot;
|
|
270
|
+
if (enableGlobDot !== undefined) {
|
|
271
|
+
globOptions.dot = enableGlobDot;
|
|
272
|
+
}
|
|
273
|
+
const filterFiles = (0, async_1.filter)(filterFilesFn(globMatcher));
|
|
274
|
+
const foundFiles = await (hasFileLists
|
|
275
|
+
? useFileLists(fileLists, allGlobs, root, enableGlobDot)
|
|
276
|
+
: (0, fileHelper_1.findFiles)(fileGlobs, globOptions));
|
|
277
|
+
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)];
|
|
281
|
+
return files;
|
|
282
|
+
}
|
|
256
283
|
function isExcluded(filename, globMatcherExclude) {
|
|
257
284
|
if (cspell.isBinaryFile(vscode_uri_1.URI.file(filename))) {
|
|
258
285
|
return true;
|
|
@@ -266,25 +293,17 @@ Options:
|
|
|
266
293
|
}
|
|
267
294
|
return r.matched;
|
|
268
295
|
}
|
|
269
|
-
function
|
|
270
|
-
const { glob, rawGlob, source } = g;
|
|
271
|
-
return {
|
|
272
|
-
glob: rawGlob || glob,
|
|
273
|
-
source,
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function filterFiles(files, globMatcherExclude) {
|
|
296
|
+
function filterFilesFn(globMatcherExclude) {
|
|
277
297
|
const patterns = globMatcherExclude.patterns;
|
|
278
298
|
const excludeInfo = patterns
|
|
279
299
|
.map(extractGlobSource)
|
|
280
300
|
.map(({ glob, source }) => `Glob: ${glob} from ${source}`)
|
|
281
301
|
.filter(util.uniqueFn());
|
|
282
302
|
reporter.info(`Exclusion Globs: \n ${excludeInfo.join('\n ')}\n`, cspell_types_1.MessageTypes.Info);
|
|
283
|
-
|
|
284
|
-
return result;
|
|
303
|
+
return (filename) => !isExcluded(filename, globMatcherExclude);
|
|
285
304
|
}
|
|
305
|
+
return _determineFilesToCheck();
|
|
286
306
|
}
|
|
287
|
-
exports.runLint = runLint;
|
|
288
307
|
function extractContext(tdo, contextRange) {
|
|
289
308
|
const { line, offset } = tdo;
|
|
290
309
|
const textOffsetInLine = offset - line.offset;
|
|
@@ -313,6 +332,13 @@ function extractContext(tdo, contextRange) {
|
|
|
313
332
|
};
|
|
314
333
|
return context;
|
|
315
334
|
}
|
|
335
|
+
function extractGlobSource(g) {
|
|
336
|
+
const { glob, rawGlob, source } = g;
|
|
337
|
+
return {
|
|
338
|
+
glob: rawGlob || glob,
|
|
339
|
+
source,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
316
342
|
function runResult(init = {}) {
|
|
317
343
|
const { files = 0, filesWithIssues = new Set(), issues = 0, errors = 0, cachedFiles = 0 } = init;
|
|
318
344
|
return { files, filesWithIssues, issues, errors, cachedFiles };
|
|
@@ -357,6 +383,7 @@ async function useFileLists(fileListFiles, includeGlobPatterns, root, dot) {
|
|
|
357
383
|
}
|
|
358
384
|
const globMatcher = new cspell_glob_1.GlobMatcher(includeGlobPatterns, options);
|
|
359
385
|
const files = await (0, fileHelper_1.readFileListFiles)(fileListFiles);
|
|
360
|
-
|
|
386
|
+
const filterFiles = (file) => globMatcher.match(file);
|
|
387
|
+
return files instanceof Array ? files.filter(filterFiles) : (0, async_1.pipeAsync)(files, (0, async_1.filter)(filterFiles));
|
|
361
388
|
}
|
|
362
389
|
//# sourceMappingURL=lint.js.map
|
package/dist/options.d.ts
CHANGED
|
@@ -58,11 +58,50 @@ export interface LinterOptions extends BaseOptions, CacheOptions {
|
|
|
58
58
|
* Files must be found and processed otherwise it is considered an error.
|
|
59
59
|
*/
|
|
60
60
|
mustFindFiles?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Stop processing and exit if an issue or error is found.
|
|
63
|
+
*/
|
|
64
|
+
failFast?: boolean;
|
|
61
65
|
}
|
|
62
66
|
export interface TraceOptions extends BaseOptions {
|
|
67
|
+
stdin?: boolean;
|
|
63
68
|
allowCompoundWords?: boolean;
|
|
64
69
|
ignoreCase?: boolean;
|
|
65
70
|
}
|
|
71
|
+
export interface SuggestionOptions extends BaseOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Strict case and accent checking
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
strict?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* List of dictionaries to use. If specified, only that list of dictionaries will be used.
|
|
79
|
+
*/
|
|
80
|
+
dictionaries?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* The number of suggestions to make.
|
|
83
|
+
* @default 8
|
|
84
|
+
*/
|
|
85
|
+
numSuggestions?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Max number of changes / edits to the word to get to a suggestion matching suggestion.
|
|
88
|
+
* @default 4
|
|
89
|
+
*/
|
|
90
|
+
numChanges?: number;
|
|
91
|
+
/**
|
|
92
|
+
* If multiple suggestions have the same edit / change "cost", then included them even if
|
|
93
|
+
* it causes more than `numSuggestions` to be returned.
|
|
94
|
+
* @default true
|
|
95
|
+
*/
|
|
96
|
+
includeTies?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Use stdin for the input
|
|
99
|
+
*/
|
|
100
|
+
useStdin?: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface LegacyOptions {
|
|
103
|
+
local?: string;
|
|
104
|
+
}
|
|
66
105
|
export interface BaseOptions {
|
|
67
106
|
/**
|
|
68
107
|
* Path to configuration file.
|
|
@@ -76,10 +115,6 @@ export interface BaseOptions {
|
|
|
76
115
|
* Locale to use.
|
|
77
116
|
*/
|
|
78
117
|
locale?: string;
|
|
79
|
-
/**
|
|
80
|
-
* @deprecated
|
|
81
|
-
*/
|
|
82
|
-
local?: string;
|
|
83
118
|
}
|
|
84
119
|
export interface LinterCliOptions extends Omit<LinterOptions, 'fileLists'> {
|
|
85
120
|
legacy?: boolean;
|
|
@@ -97,4 +132,5 @@ export interface LinterCliOptions extends Omit<LinterOptions, 'fileLists'> {
|
|
|
97
132
|
*/
|
|
98
133
|
fileList?: string[];
|
|
99
134
|
}
|
|
135
|
+
export declare function fixLegacy<T extends BaseOptions>(opts: T & LegacyOptions): Omit<T & LegacyOptions, 'local'>;
|
|
100
136
|
//# sourceMappingURL=options.d.ts.map
|
package/dist/options.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
12
|
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
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 {};
|
|
46
|
+
//# sourceMappingURL=async.d.ts.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
101
|
+
//# sourceMappingURL=async.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FileDescriptor } from 'file-entry-cache';
|
|
2
|
-
import type { FileResult } from '../../fileHelper';
|
|
2
|
+
import type { FileResult } from '../../util/fileHelper';
|
|
3
3
|
import type { CSpellLintResultCache } from './CSpellLintResultCache';
|
|
4
4
|
export declare type CachedFileResult = Omit<FileResult, 'fileInfo' | 'elapsedTimeMs'>;
|
|
5
5
|
/**
|
|
@@ -22,7 +22,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.DiskCache = void 0;
|
|
23
23
|
const fileEntryCache = __importStar(require("file-entry-cache"));
|
|
24
24
|
const path_1 = require("path");
|
|
25
|
-
const fileHelper_1 = require("../../fileHelper");
|
|
25
|
+
const fileHelper_1 = require("../../util/fileHelper");
|
|
26
26
|
/**
|
|
27
27
|
* Caches cspell results on disk
|
|
28
28
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GlobOptions } from './
|
|
1
|
+
import { GlobOptions } from './glob';
|
|
2
2
|
import { CSpellUserSettings, Document, Issue } from 'cspell-lib';
|
|
3
3
|
export interface ConfigInfo {
|
|
4
4
|
source: string;
|
|
@@ -43,7 +43,7 @@ export declare function calcFinalConfigInfo(configInfo: ConfigInfo, settingsFrom
|
|
|
43
43
|
* file will be resolved relative to the containing file.
|
|
44
44
|
* @returns - a list of files to be processed.
|
|
45
45
|
*/
|
|
46
|
-
export declare function readFileListFiles(listFiles: string[]): Promise<string[]
|
|
46
|
+
export declare function readFileListFiles(listFiles: string[]): Promise<string[] | AsyncIterable<string>>;
|
|
47
47
|
/**
|
|
48
48
|
* Read a `listFile` and return the containing file paths resolved relative to the `listFile`.
|
|
49
49
|
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
@@ -26,10 +26,12 @@ exports.readFileListFile = exports.readFileListFiles = exports.calcFinalConfigIn
|
|
|
26
26
|
const cspell = __importStar(require("cspell-lib"));
|
|
27
27
|
const fsp = __importStar(require("fs-extra"));
|
|
28
28
|
const get_stdin_1 = __importDefault(require("get-stdin"));
|
|
29
|
-
const glob_1 = require("./
|
|
29
|
+
const glob_1 = require("./glob");
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const cspell_lib_1 = require("cspell-lib");
|
|
32
|
-
const errors_1 = require("./
|
|
32
|
+
const errors_1 = require("./errors");
|
|
33
|
+
const async_1 = require("./async");
|
|
34
|
+
const stdin_1 = require("./stdin");
|
|
33
35
|
const UTF8 = 'utf8';
|
|
34
36
|
const STDIN = 'stdin';
|
|
35
37
|
async function readConfig(configFile, root) {
|
|
@@ -106,7 +108,15 @@ exports.calcFinalConfigInfo = calcFinalConfigInfo;
|
|
|
106
108
|
* @returns - a list of files to be processed.
|
|
107
109
|
*/
|
|
108
110
|
async function readFileListFiles(listFiles) {
|
|
109
|
-
|
|
111
|
+
let useStdin = false;
|
|
112
|
+
const files = listFiles.filter((file) => {
|
|
113
|
+
const isStdin = file === 'stdin';
|
|
114
|
+
useStdin = useStdin || isStdin;
|
|
115
|
+
return !isStdin;
|
|
116
|
+
});
|
|
117
|
+
const found = flatten(await Promise.all(files.map(readFileListFile)));
|
|
118
|
+
// Move `stdin` to the end.
|
|
119
|
+
return useStdin ? (0, async_1.mergeAsyncIterables)(found, (0, stdin_1.readStdin)()) : found;
|
|
110
120
|
}
|
|
111
121
|
exports.readFileListFiles = readFileListFiles;
|
|
112
122
|
/**
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.readStdin = void 0;
|
|
23
|
+
const readline = __importStar(require("readline"));
|
|
24
|
+
function readStdin() {
|
|
25
|
+
return readline.createInterface(process.stdin);
|
|
26
|
+
}
|
|
27
|
+
exports.readStdin = readStdin;
|
|
28
|
+
//# sourceMappingURL=stdin.js.map
|
package/dist/util/util.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ 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 pad(s: string, w: number): string;
|
|
8
|
+
export declare function padLeft(s: string, w: number): string;
|
|
7
9
|
export {};
|
|
8
10
|
//# 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.clean = exports.unique = exports.uniqueFilterFnGenerator = exports.uniqueFn = void 0;
|
|
3
|
+
exports.padLeft = exports.pad = 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,4 +28,16 @@ function clean(src) {
|
|
|
28
28
|
return r;
|
|
29
29
|
}
|
|
30
30
|
exports.clean = clean;
|
|
31
|
+
function pad(s, w) {
|
|
32
|
+
if (s.length >= w)
|
|
33
|
+
return s;
|
|
34
|
+
return (s + ' '.repeat(w)).slice(0, w);
|
|
35
|
+
}
|
|
36
|
+
exports.pad = pad;
|
|
37
|
+
function padLeft(s, w) {
|
|
38
|
+
if (s.length >= w)
|
|
39
|
+
return s;
|
|
40
|
+
return (' '.repeat(w) + s).slice(-w);
|
|
41
|
+
}
|
|
42
|
+
exports.padLeft = padLeft;
|
|
31
43
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.17.0-alpha.0",
|
|
4
4
|
"description": "A Spelling Checker for Code!",
|
|
5
5
|
"funding": "https://github.com/streetsidesoftware/cspell?sponsor=1",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"chalk": "^4.1.2",
|
|
73
73
|
"commander": "^8.3.0",
|
|
74
74
|
"comment-json": "^4.1.1",
|
|
75
|
-
"cspell-gitignore": "^5.
|
|
76
|
-
"cspell-glob": "^5.
|
|
77
|
-
"cspell-lib": "^5.
|
|
75
|
+
"cspell-gitignore": "^5.17.0-alpha.0",
|
|
76
|
+
"cspell-glob": "^5.17.0-alpha.0",
|
|
77
|
+
"cspell-lib": "^5.17.0-alpha.0",
|
|
78
78
|
"fast-json-stable-stringify": "^2.1.0",
|
|
79
79
|
"file-entry-cache": "^6.0.1",
|
|
80
80
|
"fs-extra": "^10.0.0",
|
|
@@ -89,8 +89,8 @@
|
|
|
89
89
|
"node": ">=12.13.0"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"@cspell/cspell-json-reporter": "^5.
|
|
93
|
-
"@cspell/cspell-types": "^5.
|
|
92
|
+
"@cspell/cspell-json-reporter": "^5.17.0-alpha.0",
|
|
93
|
+
"@cspell/cspell-types": "^5.17.0-alpha.0",
|
|
94
94
|
"@types/file-entry-cache": "^5.0.2",
|
|
95
95
|
"@types/fs-extra": "^9.0.13",
|
|
96
96
|
"@types/glob": "^7.2.0",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"minimatch": "^3.0.4",
|
|
104
104
|
"rimraf": "^3.0.2"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "d884218703cac72186fd69e8ba1e9eb78558c7ca"
|
|
107
107
|
}
|