cspell 5.15.2 → 5.15.3

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.
@@ -14,6 +14,7 @@ export declare function readConfig(configFile: string | undefined, root: string
14
14
  export interface FileInfo {
15
15
  filename: string;
16
16
  text?: string;
17
+ errorCode?: string;
17
18
  }
18
19
  export interface FileResult {
19
20
  fileInfo: FileInfo;
@@ -25,7 +26,10 @@ export interface FileResult {
25
26
  cached?: boolean;
26
27
  }
27
28
  export declare function fileInfoToDocument(fileInfo: FileInfo, languageId: string | undefined, locale: string | undefined): Document;
28
- export declare function readFileInfo(filename: string, encoding?: string): Promise<Required<FileInfo>>;
29
+ interface ReadFileInfoResult extends FileInfo {
30
+ text: string;
31
+ }
32
+ export declare function readFileInfo(filename: string, encoding?: string, handleNotFound?: boolean): Promise<ReadFileInfoResult>;
29
33
  export declare function readFile(filename: string, encoding?: string): Promise<string>;
30
34
  /**
31
35
  * Looks for matching glob patterns or stdin
@@ -47,4 +51,5 @@ export declare function readFileListFiles(listFiles: string[]): Promise<string[]
47
51
  * @returns - a list of files to be processed.
48
52
  */
49
53
  export declare function readFileListFile(listFile: string): Promise<string[]>;
54
+ export {};
50
55
  //# sourceMappingURL=fileHelper.d.ts.map
@@ -57,12 +57,15 @@ function fileInfoToDocument(fileInfo, languageId, locale) {
57
57
  return (0, cspell_lib_1.fileToDocument)(filename, text, languageId, locale);
58
58
  }
59
59
  exports.fileInfoToDocument = fileInfoToDocument;
60
- function readFileInfo(filename, encoding = UTF8) {
60
+ function readFileInfo(filename, encoding = UTF8, handleNotFound = false) {
61
61
  const pText = filename === STDIN ? (0, get_stdin_1.default)() : fsp.readFile(filename, encoding);
62
- return pText.then((text) => ({ text, filename }), (error) => {
63
- return error.code === 'EISDIR'
64
- ? Promise.resolve({ text: '', filename })
65
- : Promise.reject((0, errors_1.toApplicationError)(error, `Error reading file: "${filename}"`));
62
+ return pText.then((text) => ({ text, filename }), (e) => {
63
+ const error = (0, errors_1.toError)(e);
64
+ return handleNotFound && error.code === 'EISDIR'
65
+ ? Promise.resolve({ text: '', filename, errorCode: error.code })
66
+ : handleNotFound && error.code === 'ENOENT'
67
+ ? Promise.resolve({ text: '', filename, errorCode: error.code })
68
+ : Promise.reject(new errors_1.IOError(`Error reading file: "${filename}"`, error));
66
69
  });
67
70
  }
68
71
  exports.readFileInfo = readFileInfo;
package/dist/lint/lint.js CHANGED
@@ -50,18 +50,29 @@ async function runLint(cfg) {
50
50
  reporter.debug(`Filename: ${filename}, using cache`);
51
51
  return cachedResult;
52
52
  }
53
- const fileInfo = await (0, fileHelper_1.readFileInfo)(filename);
54
- const doc = (0, fileHelper_1.fileInfoToDocument)(fileInfo, cfg.options.languageId, cfg.locale);
55
- const { text } = fileInfo;
56
- reporter.debug(`Filename: ${filename}, LanguageIds: ${(_a = doc.languageId) !== null && _a !== void 0 ? _a : 'default'}`);
57
53
  const result = {
58
- fileInfo,
54
+ fileInfo: {
55
+ filename,
56
+ },
59
57
  issues: [],
60
58
  processed: false,
61
59
  errors: 0,
62
60
  configErrors: 0,
63
61
  elapsedTimeMs: 0,
64
62
  };
63
+ const fileInfo = await (0, fileHelper_1.readFileInfo)(filename, undefined, true);
64
+ if (fileInfo.errorCode) {
65
+ if (fileInfo.errorCode !== 'EISDIR' && cfg.options.mustFindFiles) {
66
+ const err = (0, errors_1.toError)(`File not found: "${filename}"`);
67
+ reporter.error('Linter:', err);
68
+ result.errors += 1;
69
+ }
70
+ return result;
71
+ }
72
+ const doc = (0, fileHelper_1.fileInfoToDocument)(fileInfo, cfg.options.languageId, cfg.locale);
73
+ const { text } = fileInfo;
74
+ reporter.debug(`Filename: ${filename}, LanguageIds: ${(_a = doc.languageId) !== null && _a !== void 0 ? _a : 'default'}`);
75
+ result.fileInfo = fileInfo;
65
76
  const getElapsedTimeMs = (0, timer_1.getTimeMeasurer)();
66
77
  let spellResult = {};
67
78
  reporter.info(`Checking: ${filename}, File type: ${(_b = doc.languageId) !== null && _b !== void 0 ? _b : 'auto'}, Language: ${(_c = doc.locale) !== null && _c !== void 0 ? _c : 'default'}`, cspell_types_1.MessageTypes.Info);
@@ -107,7 +118,7 @@ async function runLint(cfg) {
107
118
  filename,
108
119
  elapsedTimeMs: result === null || result === void 0 ? void 0 : result.elapsedTimeMs,
109
120
  processed: result === null || result === void 0 ? void 0 : result.processed,
110
- numErrors: result === null || result === void 0 ? void 0 : result.issues.length,
121
+ numErrors: (result === null || result === void 0 ? void 0 : result.issues.length) || (result === null || result === void 0 ? void 0 : result.errors),
111
122
  cached: result === null || result === void 0 ? void 0 : result.cached,
112
123
  });
113
124
  async function* loadAndProcessFiles() {
package/dist/options.d.ts CHANGED
@@ -54,6 +54,10 @@ export interface LinterOptions extends BaseOptions, CacheOptions {
54
54
  * - an entry of `stdin` means to read the file list from **`stdin`**
55
55
  */
56
56
  fileLists?: string[] | undefined;
57
+ /**
58
+ * Files must be found and processed otherwise it is considered an error.
59
+ */
60
+ mustFindFiles?: boolean;
57
61
  }
58
62
  export interface TraceOptions extends BaseOptions {
59
63
  allowCompoundWords?: boolean;
@@ -7,11 +7,17 @@ export declare class ApplicationError extends Error {
7
7
  readonly cause?: Error | undefined;
8
8
  constructor(message: string, exitCode?: number, cause?: Error | undefined);
9
9
  }
10
- export declare function toError(e: unknown): Error;
10
+ export declare class IOError extends ApplicationError {
11
+ readonly cause: NodeError;
12
+ constructor(message: string, cause: NodeError);
13
+ get code(): string | undefined;
14
+ isNotFound(): boolean;
15
+ }
16
+ export declare function toError(e: unknown): NodeError;
11
17
  export declare function isError(e: unknown): e is NodeError;
12
18
  export declare function toApplicationError(e: unknown, message?: string): ApplicationError;
13
- interface NodeError extends Error {
19
+ export interface NodeError extends Error {
14
20
  code?: string;
21
+ toString?: () => string;
15
22
  }
16
- export {};
17
23
  //# sourceMappingURL=errors.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toApplicationError = exports.isError = exports.toError = exports.ApplicationError = exports.CheckFailed = void 0;
3
+ exports.toApplicationError = exports.isError = exports.toError = exports.IOError = 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) {
@@ -17,12 +17,27 @@ class ApplicationError extends Error {
17
17
  }
18
18
  }
19
19
  exports.ApplicationError = ApplicationError;
20
+ class IOError extends ApplicationError {
21
+ constructor(message, cause) {
22
+ super(message, undefined, cause);
23
+ this.cause = cause;
24
+ }
25
+ get code() {
26
+ return this.cause.code;
27
+ }
28
+ isNotFound() {
29
+ return this.cause.code === 'ENOENT';
30
+ }
31
+ }
32
+ exports.IOError = IOError;
20
33
  function toError(e) {
21
34
  if (isError(e))
22
35
  return e;
36
+ const message = (0, util_1.format)(e);
23
37
  return {
24
38
  name: 'error',
25
- message: (0, util_1.format)(e),
39
+ message,
40
+ toString: () => message,
26
41
  };
27
42
  }
28
43
  exports.toError = toError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell",
3
- "version": "5.15.2",
3
+ "version": "5.15.3",
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.15.2",
76
- "cspell-glob": "^5.15.2",
77
- "cspell-lib": "^5.15.2",
75
+ "cspell-gitignore": "^5.15.3",
76
+ "cspell-glob": "^5.15.3",
77
+ "cspell-lib": "^5.15.3",
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.15.2",
93
- "@cspell/cspell-types": "^5.15.2",
92
+ "@cspell/cspell-json-reporter": "^5.15.3",
93
+ "@cspell/cspell-types": "^5.15.3",
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": "b047b5458980010a8f3ab31c6dc9434e0e782d5e"
106
+ "gitHead": "8a7c55b7d0b340d3c4e964ba91390a405f2cda2d"
107
107
  }