cspell 5.13.2 → 5.14.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 CHANGED
@@ -69,7 +69,7 @@ cspell lint --help
69
69
  ### Options
70
70
 
71
71
  ```text
72
- Usage: cspell lint [options] [files...]
72
+ Usage: cspell lint [options] [globs...]
73
73
 
74
74
  Check spelling
75
75
 
@@ -77,8 +77,8 @@ Options:
77
77
  -c, --config <cspell.json> Configuration file to use. By default cspell
78
78
  looks for cspell.json in the current directory.
79
79
 
80
- -v, --verbose display more information about the files being
81
- checked and the configuration
80
+ -v, --verbose Display more information about the files being
81
+ checked and the configuration.
82
82
 
83
83
  --locale <locale> Set language locales. i.e. "en,fr" for English
84
84
  and French, or "en-GB" for British English.
@@ -92,28 +92,30 @@ Options:
92
92
  -u, --unique Only output the first instance of a word not
93
93
  found in the dictionaries.
94
94
 
95
- --debug Output information useful for debugging
96
- cspell.json files.
97
-
98
95
  -e, --exclude <glob> Exclude files matching the glob pattern. This
99
96
  option can be used multiple times to add
100
97
  multiple globs.
101
98
 
99
+ --file-list <path or stdin> Specify a list of files to be spell checked. The
100
+ list is filtered against the glob file patterns.
101
+ Note: the format is 1 file path per line.
102
+
102
103
  --no-issues Do not show the spelling errors.
103
104
  --no-progress Turn off progress messages
104
- --no-summary Turn off summary message in console
105
- -s, --silent Silent mode, suppress error messages
105
+ --no-summary Turn off summary message in console.
106
+ -s, --silent Silent mode, suppress error messages.
106
107
  -r, --root <root folder> Root directory, defaults to current directory.
107
108
  --relative Issues are displayed relative to root.
108
109
  --show-context Show the surrounding text around an issue.
109
110
  --show-suggestions Show spelling suggestions.
110
- --no-must-find-files Do not error if no files are found
111
+ --no-must-find-files Do not error if no files are found.
111
112
 
112
- --cache Only check changed files (default: false)
113
- --cache-strategy <strategy> Strategy to use for detecting changed files
113
+ --cache Only check changed files. (default: false)
114
+
115
+ --cache-strategy <strategy> Strategy to use for detecting changed files.
114
116
  (choices: "metadata", "content")
115
117
 
116
- --cache-location <path> Path to the cache file or directory (default:
118
+ --cache-location <path> Path to the cache file or directory. (default:
117
119
  ".cspellcache")
118
120
 
119
121
  --dot Include files and directories starting with `.`
@@ -128,7 +130,9 @@ Options:
128
130
  root.
129
131
 
130
132
  --no-color Turn off color.
131
- --color Force color
133
+ --color Force color.
134
+ --debug Output information useful for debugging
135
+ cspell.json files.
132
136
  -h, --help display help for command
133
137
 
134
138
 
@@ -196,8 +200,7 @@ npm install -SD cspell
196
200
  ```
197
201
  #!/bin/sh
198
202
 
199
- files=$(git diff --cached --name-only)
200
- exec npx cspell -- --no-summary $files
203
+ exec git diff --cached --name-only | npx cspell -- --no-summary --no-progress --no-must-find-files --file-list stdin
201
204
  ```
202
205
 
203
206
  ## Requirements
package/dist/app.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as commander from 'commander';
2
- export { LinterCliOptions as Options } from './commandLint';
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 errors_1 = require("./util/errors");
32
- Object.defineProperty(exports, "CheckFailed", { enumerable: true, get: function () { return errors_1.CheckFailed; } });
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);
@@ -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(files: string[], options: LinterOptions, emitters: CSpellReporter): Promise<RunResult>;
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>;
@@ -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(files, options, emitters) {
32
- const cfg = new lint_1.LintRequest(files, options, emitters);
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;
@@ -1,9 +1,12 @@
1
1
  import type { CSpellReporter, Issue } from '@cspell/cspell-types';
2
- import { Options } from './app';
2
+ import { LinterCliOptions } from './options';
3
3
  export interface ReporterIssue extends Issue {
4
4
  filename: string;
5
5
  }
6
- export declare function getReporter(options: Options): CSpellReporter;
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;
@@ -98,7 +98,7 @@ function getReporter(options) {
98
98
  : options.showSuggestions
99
99
  ? templateIssueWithSuggestions
100
100
  : templateIssue;
101
- const { files, silent, summary, issues, progress, verbose, debug } = options;
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 (!files.length && !result.files) {
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);
@@ -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
@@ -47,50 +47,53 @@ 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', 'display more information about the files being checked and the configuration')
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
- .option('--legacy', 'Legacy output')
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', 'Only check changed files', false)
75
- .addOption(new commander_1.Option('--cache-strategy <strategy>', 'Strategy to use for detecting changed files').choices([
76
+ .option('--cache', 'Only check changed files.', false)
77
+ .addOption(new commander_1.Option('--cache-strategy <strategy>', 'Strategy to use for detecting changed files.').choices([
76
78
  'metadata',
77
79
  'content',
78
80
  ]))
79
- .option('--cache-location <path>', `Path to the cache file or directory`, cache_1.DEFAULT_CACHE_LOCATION)
81
+ .option('--cache-location <path>', `Path to the cache file or directory.`, cache_1.DEFAULT_CACHE_LOCATION)
80
82
  .option('--dot', 'Include files and directories starting with `.` (period) when matching globs.')
81
83
  .option('--gitignore', 'Ignore files matching glob patterns found in .gitignore files.')
82
84
  .option('--no-gitignore', 'Do NOT use .gitignore files.')
83
85
  .option('--gitignore-root <path>', 'Prevent searching for .gitignore files past root.', collect)
84
86
  .option('--no-color', 'Turn off color.')
85
- .option('--color', 'Force color')
87
+ .option('--color', 'Force color.')
88
+ .option('--debug', 'Output information useful for debugging cspell.json files.')
86
89
  .addHelpText('after', usage)
87
- .arguments('[files...]')
88
- .action((files, options) => {
89
- options.files = files;
90
- const { mustFindFiles } = options;
91
- const cliReporter = (0, cli_reporter_1.getReporter)(options);
92
- return App.lint(files, options, cliReporter).then((result) => {
93
- if (!files.length && !result.files) {
90
+ .arguments('[globs...]')
91
+ .action((fileGlobs, options) => {
92
+ const { mustFindFiles, fileList } = options;
93
+ const cliReporter = (0, cli_reporter_1.getReporter)({ ...options, fileGlobs });
94
+ const lintOptions = { ...options, fileLists: fileList };
95
+ return App.lint(fileGlobs, lintOptions, cliReporter).then((result) => {
96
+ if (!fileGlobs.length && !result.files && !result.errors && !fileList) {
94
97
  spellCheckCommand.outputHelp();
95
98
  throw new errors_1.CheckFailed('outputHelp', 1);
96
99
  }
@@ -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
@@ -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 files: string[];
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
- constructor(files: string[], options: LinterOptions, reporter: CSpellReporter);
15
+ readonly fileLists: string[];
16
+ constructor(fileGlobs: string[], options: LinterOptions, reporter: CSpellReporter);
16
17
  }
17
18
  //# sourceMappingURL=LintRequest.d.ts.map
@@ -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(files, options, reporter) {
29
- this.files = files;
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();
@@ -175,7 +177,7 @@ async function runLint(cfg) {
175
177
  const useGitignore = (_b = (_a = cfg.options.gitignore) !== null && _a !== void 0 ? _a : configInfo.config.useGitignore) !== null && _b !== void 0 ? _b : false;
176
178
  const gitignoreRoots = (_c = cfg.options.gitignoreRoot) !== null && _c !== void 0 ? _c : configInfo.config.gitignoreRoot;
177
179
  const gitIgnore = useGitignore ? await generateGitIgnore(gitignoreRoots) : undefined;
178
- const cliGlobs = cfg.files;
180
+ const cliGlobs = cfg.fileGlobs;
179
181
  const allGlobs = cliGlobs.length ? cliGlobs : configInfo.config.files || [];
180
182
  const combinedGlobs = (0, glob_1.normalizeGlobsToRoot)(allGlobs, cfg.root, false);
181
183
  const cliExcludeGlobs = (0, glob_1.extractPatterns)(cfg.excludes).map((p) => p.glob);
@@ -183,7 +185,8 @@ async function runLint(cfg) {
183
185
  const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
184
186
  const excludeGlobs = combinedGlobs.filter((g) => g.startsWith('!')).concat(normalizedExcludes);
185
187
  const fileGlobs = includeGlobs;
186
- if (!fileGlobs.length) {
188
+ const hasFileLists = !!fileLists.length;
189
+ if (!fileGlobs.length && !hasFileLists) {
187
190
  // Nothing to do.
188
191
  return runResult();
189
192
  }
@@ -208,10 +211,19 @@ async function runLint(cfg) {
208
211
  if (enableGlobDot !== undefined) {
209
212
  globOptions.dot = enableGlobDot;
210
213
  }
211
- const foundFiles = await (0, fileHelper_1.findFiles)(fileGlobs, globOptions);
212
- const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles;
213
- const files = filterFiles(filtered, globMatcher);
214
- return processFiles(files, configInfo, files.length);
214
+ try {
215
+ const foundFiles = await (hasFileLists
216
+ ? useFileLists(fileLists, allGlobs, root, enableGlobDot)
217
+ : (0, fileHelper_1.findFiles)(fileGlobs, globOptions));
218
+ const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles;
219
+ const files = filterFiles(filtered, globMatcher);
220
+ return await processFiles(files, configInfo, files.length);
221
+ }
222
+ catch (e) {
223
+ const err = (0, errors_1.toApplicationError)(e);
224
+ reporter.error('Linter', err);
225
+ return runResult({ errors: 1 });
226
+ }
215
227
  }
216
228
  function header(files, cliExcludes) {
217
229
  const formattedFiles = files.length > 100 ? files.slice(0, 100).concat(['...']) : files;
@@ -227,13 +239,13 @@ Options:
227
239
  unique: ${yesNo(!!cfg.options.unique)}
228
240
  `, cspell_types_1.MessageTypes.Info);
229
241
  }
230
- function isExcluded(filename, globMatcher) {
242
+ function isExcluded(filename, globMatcherExclude) {
231
243
  if (cspell.isBinaryFile(vscode_uri_1.URI.file(filename))) {
232
244
  return true;
233
245
  }
234
246
  const { root } = cfg;
235
247
  const absFilename = path.resolve(root, filename);
236
- const r = globMatcher.matchEx(absFilename);
248
+ const r = globMatcherExclude.matchEx(absFilename);
237
249
  if (r.matched) {
238
250
  const { glob, source } = extractGlobSource(r.pattern);
239
251
  reporter.info(`Excluded File: ${path.relative(root, absFilename)}; Excluded by ${glob} from ${source}`, cspell_types_1.MessageTypes.Info);
@@ -247,14 +259,14 @@ Options:
247
259
  source,
248
260
  };
249
261
  }
250
- function filterFiles(files, globMatcher) {
251
- const patterns = globMatcher.patterns;
262
+ function filterFiles(files, globMatcherExclude) {
263
+ const patterns = globMatcherExclude.patterns;
252
264
  const excludeInfo = patterns
253
265
  .map(extractGlobSource)
254
266
  .map(({ glob, source }) => `Glob: ${glob} from ${source}`)
255
267
  .filter(util.uniqueFn());
256
268
  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, globMatcher));
269
+ const result = files.filter(util.uniqueFn()).filter((filename) => !isExcluded(filename, globMatcherExclude));
258
270
  return result;
259
271
  }
260
272
  }
@@ -323,4 +335,14 @@ async function generateGitIgnore(roots) {
323
335
  }
324
336
  return new cspell_gitignore_1.GitIgnore(root === null || root === void 0 ? void 0 : root.map((p) => path.resolve(p)));
325
337
  }
338
+ async function useFileLists(fileListFiles, includeGlobPatterns, root, dot) {
339
+ includeGlobPatterns = includeGlobPatterns.length ? includeGlobPatterns : ['**'];
340
+ const options = { root, mode: 'include' };
341
+ if (dot !== undefined) {
342
+ options.dot = dot;
343
+ }
344
+ const globMatcher = new cspell_glob_1.GlobMatcher(includeGlobPatterns, options);
345
+ const files = await (0, fileHelper_1.readFileListFiles)(fileListFiles);
346
+ return files.filter((file) => globMatcher.match(file));
347
+ }
326
348
  //# sourceMappingURL=lint.js.map
package/dist/options.d.ts CHANGED
@@ -48,6 +48,12 @@ 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;
@@ -59,4 +65,20 @@ export interface BaseOptions {
59
65
  locale?: string;
60
66
  local?: string;
61
67
  }
68
+ export interface LinterCliOptions extends Omit<LinterOptions, 'fileLists'> {
69
+ legacy?: boolean;
70
+ summary: boolean;
71
+ issues: boolean;
72
+ silent: boolean;
73
+ mustFindFiles: boolean;
74
+ progress?: boolean;
75
+ /**
76
+ * issues are shown with a relative path to the root or `cwd`
77
+ */
78
+ relative?: boolean;
79
+ /**
80
+ * List of file paths to files that contains a list of files to be spell checked.
81
+ */
82
+ fileList?: string[];
83
+ }
62
84
  //# sourceMappingURL=options.d.ts.map
@@ -4,8 +4,10 @@ export declare class CheckFailed extends Error {
4
4
  }
5
5
  export declare class ApplicationError extends Error {
6
6
  readonly exitCode: number;
7
- constructor(message: string, exitCode?: number);
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
11
  export declare function isError(e: unknown): e is Error;
12
+ export declare function toApplicationError(e: unknown, message?: string): ApplicationError;
11
13
  //# sourceMappingURL=errors.d.ts.map
@@ -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.name === 'string' && typeof ex.message === 'string';
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
@@ -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.13.2",
3
+ "version": "5.14.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.13.2",
76
- "cspell-glob": "^5.13.2",
77
- "cspell-lib": "^5.13.2",
75
+ "cspell-gitignore": "^5.14.0",
76
+ "cspell-glob": "^5.14.0",
77
+ "cspell-lib": "^5.14.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.2"
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.13.2",
92
- "@cspell/cspell-types": "^5.13.2",
92
+ "@cspell/cspell-json-reporter": "^5.14.0",
93
+ "@cspell/cspell-types": "^5.14.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
- "jest": "^27.4.0",
100
+ "@types/semver": "^7.3.9",
101
+ "jest": "^27.4.5",
100
102
  "micromatch": "^4.0.4",
101
103
  "minimatch": "^3.0.4",
102
104
  "rimraf": "^3.0.2"
103
105
  },
104
- "gitHead": "98bce0c75dcf4328b0adc80a9014809b393c0d37"
106
+ "gitHead": "8c8dfb70479584839e8035094771762f77118667"
105
107
  }