cspell 5.13.3 → 5.15.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 +24 -15
- package/dist/app.d.ts +1 -1
- package/dist/app.js +7 -2
- package/dist/application.d.ts +1 -1
- package/dist/application.js +2 -2
- package/dist/cli-reporter.d.ts +5 -2
- package/dist/cli-reporter.js +2 -2
- package/dist/commandLint.d.ts +0 -14
- package/dist/commandLint.js +22 -18
- package/dist/fileHelper.d.ts +14 -0
- package/dist/fileHelper.js +43 -5
- package/dist/lint/LintRequest.d.ts +3 -2
- package/dist/lint/LintRequest.js +3 -2
- package/dist/lint/lint.js +47 -22
- package/dist/options.d.ts +34 -0
- package/dist/util/cache/CSpellLintResultCache.d.ts +3 -3
- package/dist/util/cache/CacheOptions.d.ts +2 -1
- package/dist/util/cache/DiskCache.d.ts +24 -3
- package/dist/util/cache/DiskCache.js +56 -14
- package/dist/util/cache/createCache.d.ts +5 -5
- package/dist/util/cache/createCache.js +32 -3
- package/dist/util/cache/index.d.ts +1 -2
- package/dist/util/cache/index.js +2 -1
- package/dist/util/errors.d.ts +8 -2
- package/dist/util/errors.js +11 -3
- package/dist/util/glob.d.ts +1 -1
- package/dist/util/glob.js +1 -1
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -56,6 +56,12 @@ cspell lint "src/**/*.js"
|
|
|
56
56
|
cspell "**"
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
**Git: Check Only Changed Files**
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
git diff --name-only | npx cspell --file-list stdin
|
|
63
|
+
```
|
|
64
|
+
|
|
59
65
|
## Command: `lint` -- Spell Checking
|
|
60
66
|
|
|
61
67
|
The `lint` command is used for spell checking files.
|
|
@@ -69,7 +75,7 @@ cspell lint --help
|
|
|
69
75
|
### Options
|
|
70
76
|
|
|
71
77
|
```text
|
|
72
|
-
Usage: cspell lint [options] [
|
|
78
|
+
Usage: cspell lint [options] [globs...]
|
|
73
79
|
|
|
74
80
|
Check spelling
|
|
75
81
|
|
|
@@ -77,8 +83,8 @@ Options:
|
|
|
77
83
|
-c, --config <cspell.json> Configuration file to use. By default cspell
|
|
78
84
|
looks for cspell.json in the current directory.
|
|
79
85
|
|
|
80
|
-
-v, --verbose
|
|
81
|
-
checked and the configuration
|
|
86
|
+
-v, --verbose Display more information about the files being
|
|
87
|
+
checked and the configuration.
|
|
82
88
|
|
|
83
89
|
--locale <locale> Set language locales. i.e. "en,fr" for English
|
|
84
90
|
and French, or "en-GB" for British English.
|
|
@@ -92,28 +98,30 @@ Options:
|
|
|
92
98
|
-u, --unique Only output the first instance of a word not
|
|
93
99
|
found in the dictionaries.
|
|
94
100
|
|
|
95
|
-
--debug Output information useful for debugging
|
|
96
|
-
cspell.json files.
|
|
97
|
-
|
|
98
101
|
-e, --exclude <glob> Exclude files matching the glob pattern. This
|
|
99
102
|
option can be used multiple times to add
|
|
100
103
|
multiple globs.
|
|
101
104
|
|
|
105
|
+
--file-list <path or stdin> Specify a list of files to be spell checked. The
|
|
106
|
+
list is filtered against the glob file patterns.
|
|
107
|
+
Note: the format is 1 file path per line.
|
|
108
|
+
|
|
102
109
|
--no-issues Do not show the spelling errors.
|
|
103
110
|
--no-progress Turn off progress messages
|
|
104
|
-
--no-summary Turn off summary message in console
|
|
105
|
-
-s, --silent Silent mode, suppress error messages
|
|
111
|
+
--no-summary Turn off summary message in console.
|
|
112
|
+
-s, --silent Silent mode, suppress error messages.
|
|
106
113
|
-r, --root <root folder> Root directory, defaults to current directory.
|
|
107
114
|
--relative Issues are displayed relative to root.
|
|
108
115
|
--show-context Show the surrounding text around an issue.
|
|
109
116
|
--show-suggestions Show spelling suggestions.
|
|
110
|
-
--no-must-find-files Do not error if no files are found
|
|
117
|
+
--no-must-find-files Do not error if no files are found.
|
|
111
118
|
|
|
112
|
-
--cache
|
|
113
|
-
--cache
|
|
119
|
+
--cache Use cache to only check changed files.
|
|
120
|
+
--no-cache Do not use cache.
|
|
121
|
+
--cache-strategy <strategy> Strategy to use for detecting changed files.
|
|
114
122
|
(choices: "metadata", "content")
|
|
115
123
|
|
|
116
|
-
--cache-location <path> Path to the cache file or directory (default:
|
|
124
|
+
--cache-location <path> Path to the cache file or directory. (default:
|
|
117
125
|
".cspellcache")
|
|
118
126
|
|
|
119
127
|
--dot Include files and directories starting with `.`
|
|
@@ -128,7 +136,9 @@ Options:
|
|
|
128
136
|
root.
|
|
129
137
|
|
|
130
138
|
--no-color Turn off color.
|
|
131
|
-
--color Force color
|
|
139
|
+
--color Force color.
|
|
140
|
+
--debug Output information useful for debugging
|
|
141
|
+
cspell.json files.
|
|
132
142
|
-h, --help display help for command
|
|
133
143
|
|
|
134
144
|
|
|
@@ -196,8 +206,7 @@ npm install -SD cspell
|
|
|
196
206
|
```
|
|
197
207
|
#!/bin/sh
|
|
198
208
|
|
|
199
|
-
|
|
200
|
-
exec npx cspell -- --no-summary $files
|
|
209
|
+
exec git diff --cached --name-only | npx cspell -- --no-summary --no-progress --no-must-find-files --file-list stdin
|
|
201
210
|
```
|
|
202
211
|
|
|
203
212
|
## Requirements
|
package/dist/app.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as commander from 'commander';
|
|
2
|
-
export { LinterCliOptions as Options } from './
|
|
2
|
+
export { LinterCliOptions as Options } from './options';
|
|
3
3
|
export { CheckFailed } from './util/errors';
|
|
4
4
|
export declare function run(program?: commander.Command, argv?: string[]): Promise<void>;
|
|
5
5
|
//# sourceMappingURL=app.d.ts.map
|
package/dist/app.js
CHANGED
|
@@ -22,19 +22,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.run = exports.CheckFailed = void 0;
|
|
23
23
|
const commander = __importStar(require("commander"));
|
|
24
24
|
const path = __importStar(require("path"));
|
|
25
|
+
const semver = __importStar(require("semver"));
|
|
25
26
|
const commandCheck_1 = require("./commandCheck");
|
|
26
27
|
const commandLink_1 = require("./commandLink");
|
|
27
28
|
const commandLint_1 = require("./commandLint");
|
|
28
29
|
const commandTrace_1 = require("./commandTrace");
|
|
30
|
+
const errors_1 = require("./util/errors");
|
|
29
31
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
30
32
|
const npmPackage = require(path.join(__dirname, '..', 'package.json'));
|
|
31
|
-
var
|
|
32
|
-
Object.defineProperty(exports, "CheckFailed", { enumerable: true, get: function () { return
|
|
33
|
+
var errors_2 = require("./util/errors");
|
|
34
|
+
Object.defineProperty(exports, "CheckFailed", { enumerable: true, get: function () { return errors_2.CheckFailed; } });
|
|
33
35
|
async function run(program, argv) {
|
|
34
36
|
const prog = program || commander.program;
|
|
35
37
|
const args = argv || process.argv;
|
|
36
38
|
prog.exitOverride();
|
|
37
39
|
prog.version(npmPackage.version).description('Spelling Checker for Code').name('cspell');
|
|
40
|
+
if (!semver.satisfies(process.versions.node, npmPackage.engines.node)) {
|
|
41
|
+
throw new errors_1.ApplicationError(`Unsupported NodeJS version (${process.versions.node}); ${npmPackage.engines.node} is required`);
|
|
42
|
+
}
|
|
38
43
|
(0, commandLint_1.commandLint)(prog);
|
|
39
44
|
(0, commandTrace_1.commandTrace)(prog);
|
|
40
45
|
(0, commandCheck_1.commandCheck)(prog);
|
package/dist/application.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { BaseOptions, LinterOptions, TraceOptions } from './options';
|
|
|
5
5
|
export { IncludeExcludeFlag } from 'cspell-lib';
|
|
6
6
|
export type { TraceResult } from 'cspell-lib';
|
|
7
7
|
export declare type AppError = NodeJS.ErrnoException;
|
|
8
|
-
export declare function lint(
|
|
8
|
+
export declare function lint(fileGlobs: string[], options: LinterOptions, emitters: CSpellReporter): Promise<RunResult>;
|
|
9
9
|
export declare function trace(words: string[], options: TraceOptions): Promise<TraceResult[]>;
|
|
10
10
|
export declare type CheckTextResult = CheckTextInfo;
|
|
11
11
|
export declare function checkText(filename: string, options: BaseOptions): Promise<CheckTextResult>;
|
package/dist/application.js
CHANGED
|
@@ -28,8 +28,8 @@ const lint_1 = require("./lint");
|
|
|
28
28
|
const util = __importStar(require("./util/util"));
|
|
29
29
|
var cspell_lib_2 = require("cspell-lib");
|
|
30
30
|
Object.defineProperty(exports, "IncludeExcludeFlag", { enumerable: true, get: function () { return cspell_lib_2.IncludeExcludeFlag; } });
|
|
31
|
-
function lint(
|
|
32
|
-
const cfg = new lint_1.LintRequest(
|
|
31
|
+
function lint(fileGlobs, options, emitters) {
|
|
32
|
+
const cfg = new lint_1.LintRequest(fileGlobs, options, emitters);
|
|
33
33
|
return (0, lint_1.runLint)(cfg);
|
|
34
34
|
}
|
|
35
35
|
exports.lint = lint;
|
package/dist/cli-reporter.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { CSpellReporter, Issue } from '@cspell/cspell-types';
|
|
2
|
-
import {
|
|
2
|
+
import { LinterCliOptions } from './options';
|
|
3
3
|
export interface ReporterIssue extends Issue {
|
|
4
4
|
filename: string;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export interface ReporterOptions extends Pick<LinterCliOptions, 'debug' | 'issues' | 'legacy' | 'progress' | 'relative' | 'root' | 'showContext' | 'showSuggestions' | 'silent' | 'summary' | 'verbose' | 'wordsOnly'> {
|
|
7
|
+
fileGlobs: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function getReporter(options: ReporterOptions): CSpellReporter;
|
|
7
10
|
declare function formatIssue(templateStr: string, issue: ReporterIssue, maxIssueTextWidth: number): string;
|
|
8
11
|
export declare const __testing__: {
|
|
9
12
|
formatIssue: typeof formatIssue;
|
package/dist/cli-reporter.js
CHANGED
|
@@ -98,7 +98,7 @@ function getReporter(options) {
|
|
|
98
98
|
: options.showSuggestions
|
|
99
99
|
? templateIssueWithSuggestions
|
|
100
100
|
: templateIssue;
|
|
101
|
-
const {
|
|
101
|
+
const { fileGlobs, silent, summary, issues, progress, verbose, debug } = options;
|
|
102
102
|
const emitters = {
|
|
103
103
|
Debug: !silent && debug ? (s) => console.info(chalk.cyan(s)) : nullEmitter,
|
|
104
104
|
Info: !silent && verbose ? (s) => console.info(chalk.yellow(s)) : nullEmitter,
|
|
@@ -121,7 +121,7 @@ function getReporter(options) {
|
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
const resultEmitter = (result) => {
|
|
124
|
-
if (!
|
|
124
|
+
if (!fileGlobs.length && !result.files) {
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
127
|
console.error('CSpell: Files checked: %d, Issues found: %d in %d files', result.files, result.issues, result.filesWithIssues.size);
|
package/dist/commandLint.d.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { LinterOptions } from './options';
|
|
3
|
-
export interface LinterCliOptions extends LinterOptions {
|
|
4
|
-
files: string[];
|
|
5
|
-
legacy?: boolean;
|
|
6
|
-
summary: boolean;
|
|
7
|
-
issues: boolean;
|
|
8
|
-
silent: boolean;
|
|
9
|
-
mustFindFiles: boolean;
|
|
10
|
-
progress?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* issues are shown with a relative path to the root or `cwd`
|
|
13
|
-
*/
|
|
14
|
-
relative?: boolean;
|
|
15
|
-
}
|
|
16
2
|
export declare function commandLint(prog: Command): Command;
|
|
17
3
|
//# sourceMappingURL=commandLint.d.ts.map
|
package/dist/commandLint.js
CHANGED
|
@@ -47,50 +47,54 @@ function commandLint(prog) {
|
|
|
47
47
|
spellCheckCommand
|
|
48
48
|
.description('Check spelling')
|
|
49
49
|
.option('-c, --config <cspell.json>', 'Configuration file to use. By default cspell looks for cspell.json in the current directory.')
|
|
50
|
-
.option('-v, --verbose', '
|
|
50
|
+
.option('-v, --verbose', 'Display more information about the files being checked and the configuration.')
|
|
51
51
|
.option('--locale <locale>', 'Set language locales. i.e. "en,fr" for English and French, or "en-GB" for British English.')
|
|
52
52
|
.option('--language-id <language>', 'Force programming language for unknown extensions. i.e. "php" or "scala"')
|
|
53
53
|
.addOption(new commander_1.Option('--languageId <language>', 'Force programming language for unknown extensions. i.e. "php" or "scala"').hideHelp())
|
|
54
54
|
.option('--words-only', 'Only output the words not found in the dictionaries.')
|
|
55
55
|
.addOption(new commander_1.Option('--wordsOnly', 'Only output the words not found in the dictionaries.').hideHelp())
|
|
56
56
|
.option('-u, --unique', 'Only output the first instance of a word not found in the dictionaries.')
|
|
57
|
-
.option('--debug', 'Output information useful for debugging cspell.json files.')
|
|
58
57
|
.option('-e, --exclude <glob>', 'Exclude files matching the glob pattern. This option can be used multiple times to add multiple globs. ', collect)
|
|
58
|
+
.option('--file-list <path or stdin>', 'Specify a list of files to be spell checked.' +
|
|
59
|
+
' The list is filtered against the glob file patterns.' +
|
|
60
|
+
' Note: the format is 1 file path per line.', collect)
|
|
59
61
|
.option('--no-issues', 'Do not show the spelling errors.')
|
|
60
62
|
.option('--no-progress', 'Turn off progress messages')
|
|
61
|
-
.option('--no-summary', 'Turn off summary message in console')
|
|
62
|
-
.option('-s, --silent', 'Silent mode, suppress error messages')
|
|
63
|
+
.option('--no-summary', 'Turn off summary message in console.')
|
|
64
|
+
.option('-s, --silent', 'Silent mode, suppress error messages.')
|
|
63
65
|
.option('-r, --root <root folder>', 'Root directory, defaults to current directory.')
|
|
64
66
|
.option('--relative', 'Issues are displayed relative to root.')
|
|
65
67
|
.option('--show-context', 'Show the surrounding text around an issue.')
|
|
66
68
|
.option('--show-suggestions', 'Show spelling suggestions.')
|
|
67
|
-
.addOption(new commander_1.Option('--must-find-files', 'Error if no files are found').default(true).hideHelp())
|
|
68
|
-
.option('--no-must-find-files', 'Do not error if no files are found')
|
|
69
|
+
.addOption(new commander_1.Option('--must-find-files', 'Error if no files are found.').default(true).hideHelp())
|
|
70
|
+
.option('--no-must-find-files', 'Do not error if no files are found.')
|
|
69
71
|
// The following options are planned features
|
|
70
72
|
// .option('-w, --watch', 'Watch for any changes to the matching files and report any errors')
|
|
71
73
|
// .option('--force', 'Force the exit value to always be 0')
|
|
72
|
-
.
|
|
74
|
+
.addOption(new commander_1.Option('--legacy', 'Legacy output').hideHelp())
|
|
73
75
|
.addOption(new commander_1.Option('--local <local>', 'Deprecated -- Use: --locale').hideHelp())
|
|
74
|
-
.option('--cache', '
|
|
75
|
-
.
|
|
76
|
+
.option('--cache', 'Use cache to only check changed files.')
|
|
77
|
+
.option('--no-cache', 'Do not use cache.')
|
|
78
|
+
.addOption(new commander_1.Option('--cache-strategy <strategy>', 'Strategy to use for detecting changed files.').choices([
|
|
76
79
|
'metadata',
|
|
77
80
|
'content',
|
|
78
81
|
]))
|
|
79
|
-
.option('--cache-location <path>', `Path to the cache file or directory
|
|
82
|
+
.option('--cache-location <path>', `Path to the cache file or directory. (default: "${cache_1.DEFAULT_CACHE_LOCATION}")`)
|
|
80
83
|
.option('--dot', 'Include files and directories starting with `.` (period) when matching globs.')
|
|
81
84
|
.option('--gitignore', 'Ignore files matching glob patterns found in .gitignore files.')
|
|
82
85
|
.option('--no-gitignore', 'Do NOT use .gitignore files.')
|
|
83
86
|
.option('--gitignore-root <path>', 'Prevent searching for .gitignore files past root.', collect)
|
|
84
87
|
.option('--no-color', 'Turn off color.')
|
|
85
|
-
.option('--color', 'Force color')
|
|
88
|
+
.option('--color', 'Force color.')
|
|
89
|
+
.option('--debug', 'Output information useful for debugging cspell.json files.')
|
|
86
90
|
.addHelpText('after', usage)
|
|
87
|
-
.arguments('[
|
|
88
|
-
.action((
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
return App.lint(
|
|
93
|
-
if (!
|
|
91
|
+
.arguments('[globs...]')
|
|
92
|
+
.action((fileGlobs, options) => {
|
|
93
|
+
const { mustFindFiles, fileList } = options;
|
|
94
|
+
const cliReporter = (0, cli_reporter_1.getReporter)({ ...options, fileGlobs });
|
|
95
|
+
const lintOptions = { ...options, fileLists: fileList };
|
|
96
|
+
return App.lint(fileGlobs, lintOptions, cliReporter).then((result) => {
|
|
97
|
+
if (!fileGlobs.length && !result.files && !result.errors && !fileList) {
|
|
94
98
|
spellCheckCommand.outputHelp();
|
|
95
99
|
throw new errors_1.CheckFailed('outputHelp', 1);
|
|
96
100
|
}
|
package/dist/fileHelper.d.ts
CHANGED
|
@@ -33,4 +33,18 @@ export declare function readFile(filename: string, encoding?: string): Promise<s
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function findFiles(globPatterns: string[], options: GlobOptions): Promise<string[]>;
|
|
35
35
|
export declare function calcFinalConfigInfo(configInfo: ConfigInfo, settingsFromCommandLine: CSpellUserSettings, filename: string, text: string): FileConfigInfo;
|
|
36
|
+
/**
|
|
37
|
+
* Read
|
|
38
|
+
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
39
|
+
* file will be resolved relative to the containing file.
|
|
40
|
+
* @returns - a list of files to be processed.
|
|
41
|
+
*/
|
|
42
|
+
export declare function readFileListFiles(listFiles: string[]): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Read a `listFile` and return the containing file paths resolved relative to the `listFile`.
|
|
45
|
+
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
46
|
+
* file will be resolved relative to the containing file.
|
|
47
|
+
* @returns - a list of files to be processed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function readFileListFile(listFile: string): Promise<string[]>;
|
|
36
50
|
//# sourceMappingURL=fileHelper.d.ts.map
|
package/dist/fileHelper.js
CHANGED
|
@@ -22,13 +22,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.calcFinalConfigInfo = exports.findFiles = exports.readFile = exports.readFileInfo = exports.fileInfoToDocument = exports.readConfig = void 0;
|
|
25
|
+
exports.readFileListFile = exports.readFileListFiles = exports.calcFinalConfigInfo = exports.findFiles = exports.readFile = exports.readFileInfo = exports.fileInfoToDocument = exports.readConfig = void 0;
|
|
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
29
|
const glob_1 = require("./util/glob");
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const cspell_lib_1 = require("cspell-lib");
|
|
32
|
+
const errors_1 = require("./util/errors");
|
|
32
33
|
const UTF8 = 'utf8';
|
|
33
34
|
const STDIN = 'stdin';
|
|
34
35
|
async function readConfig(configFile, root) {
|
|
@@ -61,10 +62,7 @@ function readFileInfo(filename, encoding = UTF8) {
|
|
|
61
62
|
return pText.then((text) => ({ text, filename }), (error) => {
|
|
62
63
|
return error.code === 'EISDIR'
|
|
63
64
|
? Promise.resolve({ text: '', filename })
|
|
64
|
-
: Promise.reject({
|
|
65
|
-
...error,
|
|
66
|
-
message: `Error reading file: "${filename}"`,
|
|
67
|
-
});
|
|
65
|
+
: Promise.reject((0, errors_1.toApplicationError)(error, `Error reading file: "${filename}"`));
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
68
|
exports.readFileInfo = readFileInfo;
|
|
@@ -98,4 +96,44 @@ function calcFinalConfigInfo(configInfo, settingsFromCommandLine, filename, text
|
|
|
98
96
|
};
|
|
99
97
|
}
|
|
100
98
|
exports.calcFinalConfigInfo = calcFinalConfigInfo;
|
|
99
|
+
/**
|
|
100
|
+
* Read
|
|
101
|
+
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
102
|
+
* file will be resolved relative to the containing file.
|
|
103
|
+
* @returns - a list of files to be processed.
|
|
104
|
+
*/
|
|
105
|
+
async function readFileListFiles(listFiles) {
|
|
106
|
+
return flatten(await Promise.all(listFiles.map(readFileListFile)));
|
|
107
|
+
}
|
|
108
|
+
exports.readFileListFiles = readFileListFiles;
|
|
109
|
+
/**
|
|
110
|
+
* Read a `listFile` and return the containing file paths resolved relative to the `listFile`.
|
|
111
|
+
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
112
|
+
* file will be resolved relative to the containing file.
|
|
113
|
+
* @returns - a list of files to be processed.
|
|
114
|
+
*/
|
|
115
|
+
async function readFileListFile(listFile) {
|
|
116
|
+
try {
|
|
117
|
+
const relTo = path.resolve(path.dirname(listFile));
|
|
118
|
+
const content = await readFile(listFile);
|
|
119
|
+
const lines = content
|
|
120
|
+
.split('\n')
|
|
121
|
+
.map((a) => a.trim())
|
|
122
|
+
.filter((a) => !!a)
|
|
123
|
+
.map((file) => path.resolve(relTo, file));
|
|
124
|
+
return lines;
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
throw (0, errors_1.toApplicationError)(err, `Error reading file list from: "${listFile}"`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.readFileListFile = readFileListFile;
|
|
131
|
+
function flatten(fileLists) {
|
|
132
|
+
function* f() {
|
|
133
|
+
for (const list of fileLists) {
|
|
134
|
+
yield* list;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return [...f()];
|
|
138
|
+
}
|
|
101
139
|
//# sourceMappingURL=fileHelper.js.map
|
|
@@ -2,7 +2,7 @@ import type { CSpellReporter, Issue } from '@cspell/cspell-types';
|
|
|
2
2
|
import { LinterOptions } from '../options';
|
|
3
3
|
import { GlobSrcInfo } from '../util/glob';
|
|
4
4
|
export declare class LintRequest {
|
|
5
|
-
readonly
|
|
5
|
+
readonly fileGlobs: string[];
|
|
6
6
|
readonly options: LinterOptions;
|
|
7
7
|
readonly reporter: CSpellReporter;
|
|
8
8
|
readonly uniqueFilter: (issue: Issue) => boolean;
|
|
@@ -12,6 +12,7 @@ export declare class LintRequest {
|
|
|
12
12
|
readonly root: string;
|
|
13
13
|
readonly showContext: number;
|
|
14
14
|
readonly enableGlobDot: boolean | undefined;
|
|
15
|
-
|
|
15
|
+
readonly fileLists: string[];
|
|
16
|
+
constructor(fileGlobs: string[], options: LinterOptions, reporter: CSpellReporter);
|
|
16
17
|
}
|
|
17
18
|
//# sourceMappingURL=LintRequest.d.ts.map
|
package/dist/lint/LintRequest.js
CHANGED
|
@@ -25,8 +25,8 @@ const glob_1 = require("../util/glob");
|
|
|
25
25
|
const util = __importStar(require("../util/util"));
|
|
26
26
|
const defaultContextRange = 20;
|
|
27
27
|
class LintRequest {
|
|
28
|
-
constructor(
|
|
29
|
-
this.
|
|
28
|
+
constructor(fileGlobs, options, reporter) {
|
|
29
|
+
this.fileGlobs = fileGlobs;
|
|
30
30
|
this.options = options;
|
|
31
31
|
this.reporter = reporter;
|
|
32
32
|
this.root = path.resolve(options.root || process.cwd());
|
|
@@ -37,6 +37,7 @@ class LintRequest {
|
|
|
37
37
|
this.uniqueFilter = options.unique ? util.uniqueFilterFnGenerator((issue) => issue.text) : () => true;
|
|
38
38
|
this.showContext =
|
|
39
39
|
options.showContext === true ? defaultContextRange : options.showContext ? options.showContext : 0;
|
|
40
|
+
this.fileLists = options.fileLists || [];
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
exports.LintRequest = LintRequest;
|
package/dist/lint/lint.js
CHANGED
|
@@ -23,6 +23,7 @@ exports.runLint = void 0;
|
|
|
23
23
|
const cspell_types_1 = require("@cspell/cspell-types");
|
|
24
24
|
const commentJson = __importStar(require("comment-json"));
|
|
25
25
|
const cspell_gitignore_1 = require("cspell-gitignore");
|
|
26
|
+
const cspell_glob_1 = require("cspell-glob");
|
|
26
27
|
const cspell = __importStar(require("cspell-lib"));
|
|
27
28
|
const path = __importStar(require("path"));
|
|
28
29
|
const util_1 = require("util");
|
|
@@ -36,6 +37,7 @@ const timer_1 = require("../util/timer");
|
|
|
36
37
|
const util = __importStar(require("../util/util"));
|
|
37
38
|
async function runLint(cfg) {
|
|
38
39
|
let { reporter } = cfg;
|
|
40
|
+
const { fileLists } = cfg;
|
|
39
41
|
cspell.setLogger(getLoggerFromReporter(reporter));
|
|
40
42
|
const configErrors = new Set();
|
|
41
43
|
const lintResult = await run();
|
|
@@ -43,7 +45,7 @@ async function runLint(cfg) {
|
|
|
43
45
|
return lintResult;
|
|
44
46
|
async function processFile(filename, configInfo, cache) {
|
|
45
47
|
var _a, _b, _c, _d;
|
|
46
|
-
const cachedResult = await cache.getCachedLintResults(filename
|
|
48
|
+
const cachedResult = await cache.getCachedLintResults(filename);
|
|
47
49
|
if (cachedResult) {
|
|
48
50
|
reporter.debug(`Filename: ${filename}, using cache`);
|
|
49
51
|
return cachedResult;
|
|
@@ -84,7 +86,8 @@ async function runLint(cfg) {
|
|
|
84
86
|
reporter.info(`Checked: ${filename}, File type: ${config.languageId}, Language: ${config.language} ... Issues: ${result.issues.length} ${elapsed}S`, cspell_types_1.MessageTypes.Info);
|
|
85
87
|
reporter.info(`Config file Used: ${spellResult.localConfigFilepath || configInfo.source}`, cspell_types_1.MessageTypes.Info);
|
|
86
88
|
reporter.info(`Dictionaries Used: ${dictionaries.join(', ')}`, cspell_types_1.MessageTypes.Info);
|
|
87
|
-
|
|
89
|
+
const dep = calcDependencies(config);
|
|
90
|
+
cache.setCachedLintResults(result, dep.files);
|
|
88
91
|
return result;
|
|
89
92
|
}
|
|
90
93
|
function mapIssue({ doc: _, ...tdo }) {
|
|
@@ -93,9 +96,10 @@ async function runLint(cfg) {
|
|
|
93
96
|
: { text: tdo.line.text.trimEnd(), offset: tdo.line.offset };
|
|
94
97
|
return { ...tdo, context };
|
|
95
98
|
}
|
|
96
|
-
async function processFiles(files, configInfo,
|
|
99
|
+
async function processFiles(files, configInfo, cacheSettings) {
|
|
100
|
+
const fileCount = files.length;
|
|
97
101
|
const status = runResult();
|
|
98
|
-
const cache = (0, cache_1.createCache)(
|
|
102
|
+
const cache = (0, cache_1.createCache)(cacheSettings);
|
|
99
103
|
const emitProgress = (filename, fileNum, result) => reporter.progress({
|
|
100
104
|
type: 'ProgressFileComplete',
|
|
101
105
|
fileNum,
|
|
@@ -115,12 +119,8 @@ async function runLint(cfg) {
|
|
|
115
119
|
}
|
|
116
120
|
for await (const fileP of loadAndProcessFiles()) {
|
|
117
121
|
const { filename, fileNum, result } = await fileP;
|
|
118
|
-
if (!result.fileInfo.text === undefined) {
|
|
119
|
-
status.files += result.cached ? 1 : 0;
|
|
120
|
-
emitProgress(filename, fileNum, result);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
122
|
status.files += 1;
|
|
123
|
+
status.cachedFiles += result.cached ? 1 : 0;
|
|
124
124
|
emitProgress(filename, fileNum, result);
|
|
125
125
|
// Show the spelling errors after emitting the progress.
|
|
126
126
|
result.issues.filter(cfg.uniqueFilter).forEach((issue) => reporter.issue(issue));
|
|
@@ -134,6 +134,10 @@ async function runLint(cfg) {
|
|
|
134
134
|
cache.reconcile();
|
|
135
135
|
return status;
|
|
136
136
|
}
|
|
137
|
+
function calcDependencies(config) {
|
|
138
|
+
const { configFiles, dictionaryFiles } = cspell.extractDependencies(config);
|
|
139
|
+
return { files: configFiles.concat(dictionaryFiles) };
|
|
140
|
+
}
|
|
137
141
|
async function reportConfigurationErrors(config) {
|
|
138
142
|
const errors = cspell.extractImportErrors(config);
|
|
139
143
|
let count = 0;
|
|
@@ -175,7 +179,7 @@ async function runLint(cfg) {
|
|
|
175
179
|
const useGitignore = (_b = (_a = cfg.options.gitignore) !== null && _a !== void 0 ? _a : configInfo.config.useGitignore) !== null && _b !== void 0 ? _b : false;
|
|
176
180
|
const gitignoreRoots = (_c = cfg.options.gitignoreRoot) !== null && _c !== void 0 ? _c : configInfo.config.gitignoreRoot;
|
|
177
181
|
const gitIgnore = useGitignore ? await generateGitIgnore(gitignoreRoots) : undefined;
|
|
178
|
-
const cliGlobs = cfg.
|
|
182
|
+
const cliGlobs = cfg.fileGlobs;
|
|
179
183
|
const allGlobs = cliGlobs.length ? cliGlobs : configInfo.config.files || [];
|
|
180
184
|
const combinedGlobs = (0, glob_1.normalizeGlobsToRoot)(allGlobs, cfg.root, false);
|
|
181
185
|
const cliExcludeGlobs = (0, glob_1.extractPatterns)(cfg.excludes).map((p) => p.glob);
|
|
@@ -183,7 +187,8 @@ async function runLint(cfg) {
|
|
|
183
187
|
const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
|
|
184
188
|
const excludeGlobs = combinedGlobs.filter((g) => g.startsWith('!')).concat(normalizedExcludes);
|
|
185
189
|
const fileGlobs = includeGlobs;
|
|
186
|
-
|
|
190
|
+
const hasFileLists = !!fileLists.length;
|
|
191
|
+
if (!fileGlobs.length && !hasFileLists) {
|
|
187
192
|
// Nothing to do.
|
|
188
193
|
return runResult();
|
|
189
194
|
}
|
|
@@ -208,10 +213,20 @@ async function runLint(cfg) {
|
|
|
208
213
|
if (enableGlobDot !== undefined) {
|
|
209
214
|
globOptions.dot = enableGlobDot;
|
|
210
215
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
216
|
+
try {
|
|
217
|
+
const cacheSettings = await (0, cache_1.calcCacheSettings)(configInfo.config, cfg.options, root);
|
|
218
|
+
const foundFiles = await (hasFileLists
|
|
219
|
+
? useFileLists(fileLists, allGlobs, root, enableGlobDot)
|
|
220
|
+
: (0, fileHelper_1.findFiles)(fileGlobs, globOptions));
|
|
221
|
+
const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles;
|
|
222
|
+
const files = filterFiles(filtered, globMatcher);
|
|
223
|
+
return await processFiles(files, configInfo, cacheSettings);
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
const err = (0, errors_1.toApplicationError)(e);
|
|
227
|
+
reporter.error('Linter', err);
|
|
228
|
+
return runResult({ errors: 1 });
|
|
229
|
+
}
|
|
215
230
|
}
|
|
216
231
|
function header(files, cliExcludes) {
|
|
217
232
|
const formattedFiles = files.length > 100 ? files.slice(0, 100).concat(['...']) : files;
|
|
@@ -227,13 +242,13 @@ Options:
|
|
|
227
242
|
unique: ${yesNo(!!cfg.options.unique)}
|
|
228
243
|
`, cspell_types_1.MessageTypes.Info);
|
|
229
244
|
}
|
|
230
|
-
function isExcluded(filename,
|
|
245
|
+
function isExcluded(filename, globMatcherExclude) {
|
|
231
246
|
if (cspell.isBinaryFile(vscode_uri_1.URI.file(filename))) {
|
|
232
247
|
return true;
|
|
233
248
|
}
|
|
234
249
|
const { root } = cfg;
|
|
235
250
|
const absFilename = path.resolve(root, filename);
|
|
236
|
-
const r =
|
|
251
|
+
const r = globMatcherExclude.matchEx(absFilename);
|
|
237
252
|
if (r.matched) {
|
|
238
253
|
const { glob, source } = extractGlobSource(r.pattern);
|
|
239
254
|
reporter.info(`Excluded File: ${path.relative(root, absFilename)}; Excluded by ${glob} from ${source}`, cspell_types_1.MessageTypes.Info);
|
|
@@ -247,14 +262,14 @@ Options:
|
|
|
247
262
|
source,
|
|
248
263
|
};
|
|
249
264
|
}
|
|
250
|
-
function filterFiles(files,
|
|
251
|
-
const patterns =
|
|
265
|
+
function filterFiles(files, globMatcherExclude) {
|
|
266
|
+
const patterns = globMatcherExclude.patterns;
|
|
252
267
|
const excludeInfo = patterns
|
|
253
268
|
.map(extractGlobSource)
|
|
254
269
|
.map(({ glob, source }) => `Glob: ${glob} from ${source}`)
|
|
255
270
|
.filter(util.uniqueFn());
|
|
256
271
|
reporter.info(`Exclusion Globs: \n ${excludeInfo.join('\n ')}\n`, cspell_types_1.MessageTypes.Info);
|
|
257
|
-
const result = files.filter(util.uniqueFn()).filter((filename) => !isExcluded(filename,
|
|
272
|
+
const result = files.filter(util.uniqueFn()).filter((filename) => !isExcluded(filename, globMatcherExclude));
|
|
258
273
|
return result;
|
|
259
274
|
}
|
|
260
275
|
}
|
|
@@ -288,8 +303,8 @@ function extractContext(tdo, contextRange) {
|
|
|
288
303
|
return context;
|
|
289
304
|
}
|
|
290
305
|
function runResult(init = {}) {
|
|
291
|
-
const { files = 0, filesWithIssues = new Set(), issues = 0, errors = 0 } = init;
|
|
292
|
-
return { files, filesWithIssues, issues, errors };
|
|
306
|
+
const { files = 0, filesWithIssues = new Set(), issues = 0, errors = 0, cachedFiles = 0 } = init;
|
|
307
|
+
return { files, filesWithIssues, issues, errors, cachedFiles };
|
|
293
308
|
}
|
|
294
309
|
function yesNo(value) {
|
|
295
310
|
return value ? 'Yes' : 'No';
|
|
@@ -323,4 +338,14 @@ async function generateGitIgnore(roots) {
|
|
|
323
338
|
}
|
|
324
339
|
return new cspell_gitignore_1.GitIgnore(root === null || root === void 0 ? void 0 : root.map((p) => path.resolve(p)));
|
|
325
340
|
}
|
|
341
|
+
async function useFileLists(fileListFiles, includeGlobPatterns, root, dot) {
|
|
342
|
+
includeGlobPatterns = includeGlobPatterns.length ? includeGlobPatterns : ['**'];
|
|
343
|
+
const options = { root, mode: 'include' };
|
|
344
|
+
if (dot !== undefined) {
|
|
345
|
+
options.dot = dot;
|
|
346
|
+
}
|
|
347
|
+
const globMatcher = new cspell_glob_1.GlobMatcher(includeGlobPatterns, options);
|
|
348
|
+
const files = await (0, fileHelper_1.readFileListFiles)(fileListFiles);
|
|
349
|
+
return files.filter((file) => globMatcher.match(file));
|
|
350
|
+
}
|
|
326
351
|
//# sourceMappingURL=lint.js.map
|
package/dist/options.d.ts
CHANGED
|
@@ -48,15 +48,49 @@ export interface LinterOptions extends BaseOptions, CacheOptions {
|
|
|
48
48
|
* Stop searching for a `.gitignore`s when a root is reached.
|
|
49
49
|
*/
|
|
50
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
|
+
fileLists?: string[] | undefined;
|
|
51
57
|
}
|
|
52
58
|
export interface TraceOptions extends BaseOptions {
|
|
53
59
|
allowCompoundWords?: boolean;
|
|
54
60
|
ignoreCase?: boolean;
|
|
55
61
|
}
|
|
56
62
|
export interface BaseOptions {
|
|
63
|
+
/**
|
|
64
|
+
* Path to configuration file.
|
|
65
|
+
*/
|
|
57
66
|
config?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Programming Language ID.
|
|
69
|
+
*/
|
|
58
70
|
languageId?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Locale to use.
|
|
73
|
+
*/
|
|
59
74
|
locale?: string;
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated
|
|
77
|
+
*/
|
|
60
78
|
local?: string;
|
|
61
79
|
}
|
|
80
|
+
export interface LinterCliOptions extends Omit<LinterOptions, 'fileLists'> {
|
|
81
|
+
legacy?: boolean;
|
|
82
|
+
summary: boolean;
|
|
83
|
+
issues: boolean;
|
|
84
|
+
silent: boolean;
|
|
85
|
+
mustFindFiles: boolean;
|
|
86
|
+
progress?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* issues are shown with a relative path to the root or `cwd`
|
|
89
|
+
*/
|
|
90
|
+
relative?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* List of file paths to files that contains a list of files to be spell checked.
|
|
93
|
+
*/
|
|
94
|
+
fileList?: string[];
|
|
95
|
+
}
|
|
62
96
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FileResult } from '../../fileHelper';
|
|
2
2
|
export interface CSpellLintResultCache {
|
|
3
3
|
/**
|
|
4
4
|
* Retrieve cached lint results for a given file name, if present in the cache.
|
|
5
5
|
*/
|
|
6
|
-
getCachedLintResults(filename: string
|
|
6
|
+
getCachedLintResults(filename: string): Promise<FileResult | undefined>;
|
|
7
7
|
/**
|
|
8
8
|
* Set the cached lint results.
|
|
9
9
|
*/
|
|
10
|
-
setCachedLintResults(result: FileResult,
|
|
10
|
+
setCachedLintResults(result: FileResult, dependsUponFiles: string[]): void;
|
|
11
11
|
/**
|
|
12
12
|
* Persists the in-memory cache to disk.
|
|
13
13
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CacheStrategy } from '@cspell/cspell-types';
|
|
1
2
|
export interface CacheOptions {
|
|
2
3
|
/**
|
|
3
4
|
* Store the info about processed files in order to only operate on the changed ones.
|
|
@@ -12,6 +13,6 @@ export interface CacheOptions {
|
|
|
12
13
|
/**
|
|
13
14
|
* Strategy to use for detecting changed files, default: metadata
|
|
14
15
|
*/
|
|
15
|
-
cacheStrategy?:
|
|
16
|
+
cacheStrategy?: CacheStrategy;
|
|
16
17
|
}
|
|
17
18
|
//# sourceMappingURL=CacheOptions.d.ts.map
|
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FileDescriptor } from 'file-entry-cache';
|
|
2
|
+
import type { FileResult } from '../../fileHelper';
|
|
2
3
|
import type { CSpellLintResultCache } from './CSpellLintResultCache';
|
|
4
|
+
export declare type CachedFileResult = Omit<FileResult, 'fileInfo' | 'elapsedTimeMs'>;
|
|
5
|
+
/**
|
|
6
|
+
* This is the data cached.
|
|
7
|
+
* Property names are short to help keep the cache file size small.
|
|
8
|
+
*/
|
|
9
|
+
interface CachedData {
|
|
10
|
+
/** results */
|
|
11
|
+
r: CachedFileResult;
|
|
12
|
+
/** dependencies */
|
|
13
|
+
d: string[];
|
|
14
|
+
}
|
|
15
|
+
interface CSpellCachedMetaData {
|
|
16
|
+
data?: CachedData;
|
|
17
|
+
}
|
|
18
|
+
export declare type CSpellCacheMeta = (FileDescriptor['meta'] & CSpellCachedMetaData) | undefined;
|
|
3
19
|
/**
|
|
4
20
|
* Caches cspell results on disk
|
|
5
21
|
*/
|
|
6
22
|
export declare class DiskCache implements CSpellLintResultCache {
|
|
7
23
|
private fileEntryCache;
|
|
24
|
+
private changedDependencies;
|
|
25
|
+
private knownDependencies;
|
|
8
26
|
constructor(cacheFileLocation: string, useCheckSum: boolean);
|
|
9
|
-
getCachedLintResults(filename: string
|
|
10
|
-
setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }: FileResult,
|
|
27
|
+
getCachedLintResults(filename: string): Promise<FileResult | undefined>;
|
|
28
|
+
setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }: FileResult, dependsUponFiles: string[]): void;
|
|
11
29
|
reconcile(): void;
|
|
30
|
+
private cacheDependencies;
|
|
31
|
+
private checkDependencies;
|
|
12
32
|
}
|
|
33
|
+
export {};
|
|
13
34
|
//# sourceMappingURL=DiskCache.d.ts.map
|
|
@@ -1,53 +1,95 @@
|
|
|
1
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
|
+
};
|
|
2
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
22
|
exports.DiskCache = void 0;
|
|
4
|
-
const
|
|
23
|
+
const fileEntryCache = __importStar(require("file-entry-cache"));
|
|
24
|
+
const path_1 = require("path");
|
|
5
25
|
const fileHelper_1 = require("../../fileHelper");
|
|
6
|
-
const getConfigHash_1 = require("./getConfigHash");
|
|
7
26
|
/**
|
|
8
27
|
* Caches cspell results on disk
|
|
9
28
|
*/
|
|
10
29
|
class DiskCache {
|
|
11
30
|
constructor(cacheFileLocation, useCheckSum) {
|
|
12
|
-
this.
|
|
31
|
+
this.changedDependencies = new Set();
|
|
32
|
+
this.knownDependencies = new Set();
|
|
33
|
+
this.fileEntryCache = fileEntryCache.createFromFile((0, path_1.resolve)(cacheFileLocation), useCheckSum);
|
|
13
34
|
}
|
|
14
|
-
async getCachedLintResults(filename
|
|
35
|
+
async getCachedLintResults(filename) {
|
|
15
36
|
const fileDescriptor = this.fileEntryCache.getFileDescriptor(filename);
|
|
16
37
|
const meta = fileDescriptor.meta;
|
|
38
|
+
const data = meta === null || meta === void 0 ? void 0 : meta.data;
|
|
39
|
+
const result = data === null || data === void 0 ? void 0 : data.r;
|
|
17
40
|
// Cached lint results are valid if and only if:
|
|
18
41
|
// 1. The file is present in the filesystem
|
|
19
42
|
// 2. The file has not changed since the time it was previously linted
|
|
20
43
|
// 3. The CSpell configuration has not changed since the time the file was previously linted
|
|
21
44
|
// If any of these are not true, we will not reuse the lint results.
|
|
22
|
-
if (fileDescriptor.notFound ||
|
|
23
|
-
fileDescriptor.changed ||
|
|
24
|
-
!meta ||
|
|
25
|
-
meta.configHash !== (0, getConfigHash_1.getConfigHash)(configInfo)) {
|
|
45
|
+
if (fileDescriptor.notFound || fileDescriptor.changed || !meta || !result || !this.checkDependencies(data.d)) {
|
|
26
46
|
return undefined;
|
|
27
47
|
}
|
|
28
48
|
// Skip reading empty files and files without lint error
|
|
29
|
-
const hasErrors =
|
|
30
|
-
const cached =
|
|
49
|
+
const hasErrors = !!result && (result.errors > 0 || result.configErrors > 0 || result.issues.length > 0);
|
|
50
|
+
const cached = true;
|
|
31
51
|
const shouldReadFile = cached && hasErrors;
|
|
32
52
|
return {
|
|
33
|
-
...
|
|
53
|
+
...result,
|
|
34
54
|
elapsedTimeMs: undefined,
|
|
35
55
|
fileInfo: shouldReadFile ? await (0, fileHelper_1.readFileInfo)(filename) : { filename },
|
|
36
56
|
cached,
|
|
37
57
|
};
|
|
38
58
|
}
|
|
39
|
-
setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result },
|
|
59
|
+
setCachedLintResults({ fileInfo, elapsedTimeMs: _, ...result }, dependsUponFiles) {
|
|
40
60
|
const fileDescriptor = this.fileEntryCache.getFileDescriptor(fileInfo.filename);
|
|
41
61
|
const meta = fileDescriptor.meta;
|
|
42
62
|
if (fileDescriptor.notFound || !meta) {
|
|
43
63
|
return;
|
|
44
64
|
}
|
|
45
|
-
|
|
46
|
-
|
|
65
|
+
const data = {
|
|
66
|
+
r: result,
|
|
67
|
+
d: dependsUponFiles,
|
|
68
|
+
};
|
|
69
|
+
meta.data = data;
|
|
70
|
+
this.cacheDependencies(dependsUponFiles);
|
|
47
71
|
}
|
|
48
72
|
reconcile() {
|
|
49
73
|
this.fileEntryCache.reconcile();
|
|
50
74
|
}
|
|
75
|
+
cacheDependencies(files) {
|
|
76
|
+
this.fileEntryCache.analyzeFiles(files);
|
|
77
|
+
}
|
|
78
|
+
checkDependencies(files) {
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
if (this.changedDependencies.has(file)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const unknown = files.filter((f) => !this.knownDependencies.has(f));
|
|
85
|
+
if (!unknown.length) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
const { changedFiles, notFoundFiles } = this.fileEntryCache.analyzeFiles(files);
|
|
89
|
+
changedFiles.map((f) => this.changedDependencies.add(f));
|
|
90
|
+
unknown.forEach((f) => this.knownDependencies.add(f));
|
|
91
|
+
return changedFiles.length === 0 && notFoundFiles.length === 0;
|
|
92
|
+
}
|
|
51
93
|
}
|
|
52
94
|
exports.DiskCache = DiskCache;
|
|
53
95
|
//# sourceMappingURL=DiskCache.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CacheSettings, CSpellSettings } from '@cspell/cspell-types';
|
|
2
|
+
import { CacheOptions } from '.';
|
|
2
3
|
import { CSpellLintResultCache } from './CSpellLintResultCache';
|
|
3
4
|
export declare const DEFAULT_CACHE_LOCATION = ".cspellcache";
|
|
4
|
-
export
|
|
5
|
-
root: string;
|
|
6
|
-
}
|
|
5
|
+
export declare type CreateCacheSettings = Required<CacheSettings>;
|
|
7
6
|
/**
|
|
8
7
|
* Creates CSpellLintResultCache (disk cache if caching is enabled in config or dummy otherwise)
|
|
9
8
|
*/
|
|
10
|
-
export declare function createCache(options:
|
|
9
|
+
export declare function createCache(options: CreateCacheSettings): CSpellLintResultCache;
|
|
10
|
+
export declare function calcCacheSettings(config: CSpellSettings, cacheOptions: CacheOptions, root: string): Promise<CreateCacheSettings>;
|
|
11
11
|
//# sourceMappingURL=createCache.d.ts.map
|
|
@@ -3,18 +3,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createCache = exports.DEFAULT_CACHE_LOCATION = void 0;
|
|
6
|
+
exports.calcCacheSettings = exports.createCache = exports.DEFAULT_CACHE_LOCATION = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const DiskCache_1 = require("./DiskCache");
|
|
9
9
|
const DummyCache_1 = require("./DummyCache");
|
|
10
|
+
const fs_extra_1 = require("fs-extra");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
10
12
|
// cspell:word cspellcache
|
|
11
13
|
exports.DEFAULT_CACHE_LOCATION = '.cspellcache';
|
|
12
14
|
/**
|
|
13
15
|
* Creates CSpellLintResultCache (disk cache if caching is enabled in config or dummy otherwise)
|
|
14
16
|
*/
|
|
15
17
|
function createCache(options) {
|
|
16
|
-
const {
|
|
17
|
-
return
|
|
18
|
+
const { useCache, cacheLocation, cacheStrategy } = options;
|
|
19
|
+
return useCache ? new DiskCache_1.DiskCache(path_1.default.resolve(cacheLocation), cacheStrategy === 'content') : new DummyCache_1.DummyCache();
|
|
18
20
|
}
|
|
19
21
|
exports.createCache = createCache;
|
|
22
|
+
async function calcCacheSettings(config, cacheOptions, root) {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
24
|
+
const cs = (_a = config.cache) !== null && _a !== void 0 ? _a : {};
|
|
25
|
+
const useCache = (_c = (_b = cacheOptions.cache) !== null && _b !== void 0 ? _b : cs.useCache) !== null && _c !== void 0 ? _c : false;
|
|
26
|
+
const cacheLocation = await resolveCacheLocation(path_1.default.resolve(root, (_e = (_d = cacheOptions.cacheLocation) !== null && _d !== void 0 ? _d : cs.cacheLocation) !== null && _e !== void 0 ? _e : exports.DEFAULT_CACHE_LOCATION));
|
|
27
|
+
const cacheStrategy = (_g = (_f = cacheOptions.cacheStrategy) !== null && _f !== void 0 ? _f : cs.cacheStrategy) !== null && _g !== void 0 ? _g : 'metadata';
|
|
28
|
+
return {
|
|
29
|
+
useCache,
|
|
30
|
+
cacheLocation,
|
|
31
|
+
cacheStrategy,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.calcCacheSettings = calcCacheSettings;
|
|
35
|
+
async function resolveCacheLocation(cacheLocation) {
|
|
36
|
+
try {
|
|
37
|
+
const s = await (0, fs_extra_1.stat)(cacheLocation);
|
|
38
|
+
if (s.isFile())
|
|
39
|
+
return cacheLocation;
|
|
40
|
+
return path_1.default.join(cacheLocation, exports.DEFAULT_CACHE_LOCATION);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if ((0, errors_1.isError)(err) && err.code === 'ENOENT') {
|
|
44
|
+
return cacheLocation;
|
|
45
|
+
}
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
20
49
|
//# sourceMappingURL=createCache.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { createCache, DEFAULT_CACHE_LOCATION } from './createCache';
|
|
2
|
-
export type { CreateCacheOptions } from './createCache';
|
|
1
|
+
export { createCache, calcCacheSettings, DEFAULT_CACHE_LOCATION, type CreateCacheSettings } from './createCache';
|
|
3
2
|
export type { CSpellLintResultCache } from './CSpellLintResultCache';
|
|
4
3
|
export type { CacheOptions } from './CacheOptions';
|
|
5
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/cache/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_CACHE_LOCATION = exports.createCache = void 0;
|
|
3
|
+
exports.DEFAULT_CACHE_LOCATION = exports.calcCacheSettings = exports.createCache = void 0;
|
|
4
4
|
var createCache_1 = require("./createCache");
|
|
5
5
|
Object.defineProperty(exports, "createCache", { enumerable: true, get: function () { return createCache_1.createCache; } });
|
|
6
|
+
Object.defineProperty(exports, "calcCacheSettings", { enumerable: true, get: function () { return createCache_1.calcCacheSettings; } });
|
|
6
7
|
Object.defineProperty(exports, "DEFAULT_CACHE_LOCATION", { enumerable: true, get: function () { return createCache_1.DEFAULT_CACHE_LOCATION; } });
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/util/errors.d.ts
CHANGED
|
@@ -4,8 +4,14 @@ export declare class CheckFailed extends Error {
|
|
|
4
4
|
}
|
|
5
5
|
export declare class ApplicationError extends Error {
|
|
6
6
|
readonly exitCode: number;
|
|
7
|
-
|
|
7
|
+
readonly cause?: Error | undefined;
|
|
8
|
+
constructor(message: string, exitCode?: number, cause?: Error | undefined);
|
|
8
9
|
}
|
|
9
10
|
export declare function toError(e: unknown): Error;
|
|
10
|
-
export declare function isError(e: unknown): e is
|
|
11
|
+
export declare function isError(e: unknown): e is NodeError;
|
|
12
|
+
export declare function toApplicationError(e: unknown, message?: string): ApplicationError;
|
|
13
|
+
interface NodeError extends Error {
|
|
14
|
+
code?: string;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
11
17
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/util/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isError = exports.toError = exports.ApplicationError = exports.CheckFailed = void 0;
|
|
3
|
+
exports.toApplicationError = exports.isError = exports.toError = exports.ApplicationError = exports.CheckFailed = void 0;
|
|
4
4
|
const util_1 = require("util");
|
|
5
5
|
class CheckFailed extends Error {
|
|
6
6
|
constructor(message, exitCode = 1) {
|
|
@@ -10,9 +10,10 @@ class CheckFailed extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
exports.CheckFailed = CheckFailed;
|
|
12
12
|
class ApplicationError extends Error {
|
|
13
|
-
constructor(message, exitCode = 1) {
|
|
13
|
+
constructor(message, exitCode = 1, cause) {
|
|
14
14
|
super(message);
|
|
15
15
|
this.exitCode = exitCode;
|
|
16
|
+
this.cause = cause;
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
exports.ApplicationError = ApplicationError;
|
|
@@ -31,7 +32,14 @@ function isError(e) {
|
|
|
31
32
|
if (!e || typeof e !== 'object')
|
|
32
33
|
return false;
|
|
33
34
|
const ex = e;
|
|
34
|
-
return typeof ex.
|
|
35
|
+
return typeof ex.message === 'string';
|
|
35
36
|
}
|
|
36
37
|
exports.isError = isError;
|
|
38
|
+
function toApplicationError(e, message) {
|
|
39
|
+
if (e instanceof ApplicationError && !message)
|
|
40
|
+
return e;
|
|
41
|
+
const err = toError(e);
|
|
42
|
+
return new ApplicationError(message !== null && message !== void 0 ? message : err.message, undefined, err);
|
|
43
|
+
}
|
|
44
|
+
exports.toApplicationError = toApplicationError;
|
|
37
45
|
//# sourceMappingURL=errors.js.map
|
package/dist/util/glob.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare function calcExcludeGlobInfo(root: string, commandLineExclude: st
|
|
|
25
25
|
export declare function extractGlobExcludesFromConfig(root: string, source: string, config: CSpellUserSettings): GlobSrcInfo[];
|
|
26
26
|
/**
|
|
27
27
|
* Build GlobMatcher from command line or config file globs.
|
|
28
|
-
* @param globs Glob patterns
|
|
28
|
+
* @param globs Glob patterns or file paths
|
|
29
29
|
* @param root - directory to use as the root
|
|
30
30
|
*/
|
|
31
31
|
export declare function buildGlobMatcher(globs: Glob[], root: string, isExclude: boolean): GlobMatcher;
|
package/dist/util/glob.js
CHANGED
|
@@ -120,7 +120,7 @@ function extractGlobExcludesFromConfig(root, source, config) {
|
|
|
120
120
|
exports.extractGlobExcludesFromConfig = extractGlobExcludesFromConfig;
|
|
121
121
|
/**
|
|
122
122
|
* Build GlobMatcher from command line or config file globs.
|
|
123
|
-
* @param globs Glob patterns
|
|
123
|
+
* @param globs Glob patterns or file paths
|
|
124
124
|
* @param root - directory to use as the root
|
|
125
125
|
*/
|
|
126
126
|
function buildGlobMatcher(globs, root, isExclude) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.15.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,34 +72,36 @@
|
|
|
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.15.0",
|
|
76
|
+
"cspell-glob": "^5.15.0",
|
|
77
|
+
"cspell-lib": "^5.15.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",
|
|
81
81
|
"get-stdin": "^8.0.0",
|
|
82
82
|
"glob": "^7.2.0",
|
|
83
83
|
"imurmurhash": "^0.1.4",
|
|
84
|
+
"semver": "^7.3.5",
|
|
84
85
|
"strip-ansi": "^6.0.1",
|
|
85
|
-
"vscode-uri": "^3.0.
|
|
86
|
+
"vscode-uri": "^3.0.3"
|
|
86
87
|
},
|
|
87
88
|
"engines": {
|
|
88
89
|
"node": ">=12.13.0"
|
|
89
90
|
},
|
|
90
91
|
"devDependencies": {
|
|
91
|
-
"@cspell/cspell-json-reporter": "^5.
|
|
92
|
-
"@cspell/cspell-types": "^5.
|
|
92
|
+
"@cspell/cspell-json-reporter": "^5.15.0",
|
|
93
|
+
"@cspell/cspell-types": "^5.15.0",
|
|
93
94
|
"@types/file-entry-cache": "^5.0.2",
|
|
94
95
|
"@types/fs-extra": "^9.0.13",
|
|
95
96
|
"@types/glob": "^7.2.0",
|
|
96
97
|
"@types/imurmurhash": "^0.1.1",
|
|
97
98
|
"@types/micromatch": "^4.0.2",
|
|
98
99
|
"@types/minimatch": "^3.0.5",
|
|
99
|
-
"
|
|
100
|
+
"@types/semver": "^7.3.9",
|
|
101
|
+
"jest": "^27.4.6",
|
|
100
102
|
"micromatch": "^4.0.4",
|
|
101
103
|
"minimatch": "^3.0.4",
|
|
102
104
|
"rimraf": "^3.0.2"
|
|
103
105
|
},
|
|
104
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "04d61378054cbecd28df100ca704c7322abab8ba"
|
|
105
107
|
}
|