@cspell/eslint-plugin 8.7.0 → 8.8.1

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
@@ -140,6 +140,12 @@ interface Options {
140
140
  * @default true
141
141
  */
142
142
  checkComments?: boolean;
143
+ /**
144
+ * Path to the cspell configuration file.
145
+ * Relative paths, will be relative to the current working directory.
146
+ * @since 8.8.0
147
+ */
148
+ configFile?: string;
143
149
  /**
144
150
  * Some CSpell Settings
145
151
  */
@@ -246,6 +252,22 @@ export default [
246
252
  }
247
253
  ```
248
254
 
255
+ ## `configFile` - Using a CSpell Configuration File
256
+
257
+ **`eslint.config.mjs`**
258
+
259
+ ```js
260
+ rules: {
261
+ '@cspell/spellchecker': [
262
+ 'error',
263
+ {
264
+ //
265
+ configFile: new URL('./cspell.config.yaml', import.meta.url).toString(),
266
+ },
267
+ ],
268
+ },
269
+ ```
270
+
249
271
  ## `autoFix`
250
272
 
251
273
  When enabled, `autoFix` corrects any spelling issues that have a single "preferred" suggestion. It attempts to match
@@ -33,6 +33,10 @@
33
33
  "description": "Spell check strings",
34
34
  "type": "boolean"
35
35
  },
36
+ "configFile": {
37
+ "description": "Path to the cspell configuration file. Relative paths, will be relative to the current working directory.",
38
+ "type": "string"
39
+ },
36
40
  "cspell": {
37
41
  "additionalProperties": false,
38
42
  "description": "CSpell options to pass to the spell checker.",
@@ -45,8 +49,19 @@
45
49
  "dictionaries": {
46
50
  "description": "Optional list of dictionaries to use. Each entry should match the name of the dictionary.\n\nTo remove a dictionary from the list, add `!` before the name.\n\nFor example, `!typescript` will turn off the dictionary with the name `typescript`.\n\nSee the [Dictionaries](https://cspell.org/docs/dictionaries/) and [Custom Dictionaries](https://cspell.org/docs/dictionaries-custom/) for more details.",
47
51
  "items": {
48
- "description": "Reference to a dictionary by name. One of:\n- {@link DictionaryRef } \n- {@link DictionaryNegRef }",
49
- "type": "string"
52
+ "anyOf": [
53
+ {
54
+ "description": "This a reference to a named dictionary. It is expected to match the name of a dictionary.",
55
+ "pattern": "^(?=[^!*,;{}[\\]~\\n]+$)(?=(.*\\w)).+$",
56
+ "type": "string"
57
+ },
58
+ {
59
+ "description": "This a negative reference to a named dictionary.\n\nIt is used to exclude or include a dictionary by name.\n\nThe reference starts with 1 or more `!`.\n- `!<dictionary_name>` - Used to exclude the dictionary matching `<dictionary_name>`.\n- `!!<dictionary_name>` - Used to re-include a dictionary matching `<dictionary_name>`. Overrides `!<dictionary_name>`.\n- `!!!<dictionary_name>` - Used to exclude a dictionary matching `<dictionary_name>`. Overrides `!!<dictionary_name>`.",
60
+ "pattern": "^(?=!+[^!*,;{}[\\]~\\n]+$)(?=(.*\\w)).+$",
61
+ "type": "string"
62
+ }
63
+ ],
64
+ "description": "Reference to a dictionary by name. One of:\n- {@link DictionaryRef } \n- {@link DictionaryNegRef }"
50
65
  },
51
66
  "type": "array"
52
67
  },
@@ -122,8 +137,49 @@
122
137
  "ignoreRegExpList": {
123
138
  "description": "List of regular expression patterns or pattern names to exclude from spell checking.\n\nExample: `[\"href\"]` - to exclude html href pattern.\n\nRegular expressions use JavaScript regular expression syntax.\n\nExample: to ignore ALL-CAPS words\n\nJSON ```json \"ignoreRegExpList\": [\"/\\\\b[A-Z]+\\\\b/g\"] ```\n\nYAML ```yaml ignoreRegExpList: - >- /\\b[A-Z]+\\b/g ```\n\nBy default, several patterns are excluded. See [Configuration](https://cspell.org/configuration/patterns) for more details.\n\nWhile you can create your own patterns, you can also leverage several patterns that are [built-in to CSpell](https://cspell.org/types/cspell-types/types/PredefinedPatterns.html).",
124
139
  "items": {
125
- "description": "A PatternRef is a Pattern or PatternId.",
126
- "type": "string"
140
+ "anyOf": [
141
+ {
142
+ "type": "string"
143
+ },
144
+ {
145
+ "description": "This matches the name in a pattern definition.",
146
+ "type": "string"
147
+ },
148
+ {
149
+ "enum": [
150
+ "Base64",
151
+ "Base64MultiLine",
152
+ "Base64SingleLine",
153
+ "CStyleComment",
154
+ "CStyleHexValue",
155
+ "CSSHexValue",
156
+ "CommitHash",
157
+ "CommitHashLink",
158
+ "Email",
159
+ "EscapeCharacters",
160
+ "HexValues",
161
+ "href",
162
+ "PhpHereDoc",
163
+ "PublicKey",
164
+ "RsaCert",
165
+ "SshRsa",
166
+ "SHA",
167
+ "HashStrings",
168
+ "SpellCheckerDisable",
169
+ "SpellCheckerDisableBlock",
170
+ "SpellCheckerDisableLine",
171
+ "SpellCheckerDisableNext",
172
+ "SpellCheckerIgnoreInDocSetting",
173
+ "string",
174
+ "UnicodeRef",
175
+ "Urls",
176
+ "UUID",
177
+ "Everything"
178
+ ],
179
+ "type": "string"
180
+ }
181
+ ],
182
+ "description": "A PatternRef is a Pattern or PatternId."
127
183
  },
128
184
  "type": "array"
129
185
  },
@@ -153,8 +209,49 @@
153
209
  "includeRegExpList": {
154
210
  "description": "List of regular expression patterns or defined pattern names to match for spell checking.\n\nIf this property is defined, only text matching the included patterns will be checked.\n\nWhile you can create your own patterns, you can also leverage several patterns that are [built-in to CSpell](https://cspell.org/types/cspell-types/types/PredefinedPatterns.html).",
155
211
  "items": {
156
- "description": "A PatternRef is a Pattern or PatternId.",
157
- "type": "string"
212
+ "anyOf": [
213
+ {
214
+ "type": "string"
215
+ },
216
+ {
217
+ "description": "This matches the name in a pattern definition.",
218
+ "type": "string"
219
+ },
220
+ {
221
+ "enum": [
222
+ "Base64",
223
+ "Base64MultiLine",
224
+ "Base64SingleLine",
225
+ "CStyleComment",
226
+ "CStyleHexValue",
227
+ "CSSHexValue",
228
+ "CommitHash",
229
+ "CommitHashLink",
230
+ "Email",
231
+ "EscapeCharacters",
232
+ "HexValues",
233
+ "href",
234
+ "PhpHereDoc",
235
+ "PublicKey",
236
+ "RsaCert",
237
+ "SshRsa",
238
+ "SHA",
239
+ "HashStrings",
240
+ "SpellCheckerDisable",
241
+ "SpellCheckerDisableBlock",
242
+ "SpellCheckerDisableLine",
243
+ "SpellCheckerDisableNext",
244
+ "SpellCheckerIgnoreInDocSetting",
245
+ "string",
246
+ "UnicodeRef",
247
+ "Urls",
248
+ "UUID",
249
+ "Everything"
250
+ ],
251
+ "type": "string"
252
+ }
253
+ ],
254
+ "description": "A PatternRef is a Pattern or PatternId."
158
255
  },
159
256
  "type": "array"
160
257
  },
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getDefaultLogger = exports.Logger = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const util_1 = require("util");
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const node_util_1 = require("node:util");
10
10
  const debugMode = false;
11
11
  class Logger {
12
12
  options;
@@ -17,9 +17,9 @@ class Logger {
17
17
  useAsync = false;
18
18
  constructor(options) {
19
19
  this.options = options;
20
- this.cwd = path_1.default.resolve(options.cwd || '.');
20
+ this.cwd = node_path_1.default.resolve(options.cwd || '.');
21
21
  const logFileBasename = options.logFile || '.cspell-eslint-plugin.log';
22
- this.logFile = path_1.default.resolve(this.cwd, logFileBasename);
22
+ this.logFile = node_path_1.default.resolve(this.cwd, logFileBasename);
23
23
  this.logToFile = options.logToFile ?? true;
24
24
  this.enabled = options.enabled ?? debugMode;
25
25
  this.useAsync = options.useAsync ?? false;
@@ -29,10 +29,10 @@ class Logger {
29
29
  return;
30
30
  if (!this.logToFile)
31
31
  return console.log(...p);
32
- const message = new Date().toISOString() + ' ' + prefixLines((0, util_1.format)(...p), ' ') + '\n';
32
+ const message = new Date().toISOString() + ' ' + prefixLines((0, node_util_1.format)(...p), ' ') + '\n';
33
33
  this.useAsync
34
- ? fs_1.default.appendFile(this.logFile, message, (err) => err && console.error(err))
35
- : fs_1.default.appendFileSync(this.logFile, message);
34
+ ? node_fs_1.default.appendFile(this.logFile, message, (err) => err && console.error(err))
35
+ : node_fs_1.default.appendFileSync(this.logFile, message);
36
36
  return;
37
37
  }
38
38
  log = this._log.bind(this);
@@ -71,6 +71,12 @@ export interface Check {
71
71
  * @default true
72
72
  */
73
73
  checkComments?: boolean;
74
+ /**
75
+ * Path to the cspell configuration file.
76
+ * Relative paths, will be relative to the current working directory.
77
+ * @since 8.8.0
78
+ */
79
+ configFile?: string;
74
80
  /**
75
81
  * CSpell options to pass to the spell checker.
76
82
  */
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.plugin = exports.configs = exports.meta = exports.rules = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
4
+ // cspell:ignore TSESTree
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
6
7
  const synckit_1 = require("synckit");
7
8
  const logger_cjs_1 = require("../common/logger.cjs");
8
9
  const defaultCheckOptions_cjs_1 = require("./defaultCheckOptions.cjs");
9
- const optionsSchema = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../assets/options.schema.json'), 'utf8'));
10
+ const optionsSchema = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '../../assets/options.schema.json'), 'utf8'));
10
11
  const schema = optionsSchema;
11
- const spellCheck = (0, synckit_1.createSyncFn)(require.resolve('../worker/worker.mjs'), 30000);
12
+ // eslint-disable-next-line n/no-missing-require
13
+ const spellCheck = (0, synckit_1.createSyncFn)(require.resolve('../worker/worker.mjs'), 30_000);
12
14
  const messages = {
13
15
  wordUnknown: 'Unknown word: "{{word}}"',
14
16
  wordForbidden: 'Forbidden word: "{{word}}"',
@@ -27,6 +29,7 @@ const ruleMeta = {
27
29
  };
28
30
  let isDebugMode = false;
29
31
  function nullFix() {
32
+ // eslint-disable-next-line unicorn/no-null
30
33
  return null;
31
34
  }
32
35
  function create(context) {
@@ -11,7 +11,7 @@ export declare const plugin: {
11
11
  rules: {
12
12
  spellchecker: Rule.RuleModule;
13
13
  };
14
- configs: Record<string, ESLint.ConfigData<import("eslint").Linter.RulesRecord> | import("eslint").Linter.FlatConfig | import("eslint").Linter.FlatConfig[]>;
14
+ configs: Record<string, ESLint.ConfigData<import("eslint").Linter.RulesRecord> | import("eslint").Linter.FlatConfig<import("eslint").Linter.RulesRecord> | import("eslint").Linter.FlatConfig<import("eslint").Linter.RulesRecord>[]>;
15
15
  meta: {
16
16
  readonly name: "@cspell";
17
17
  };
@@ -7,6 +7,7 @@ exports.defaultCheckOptions = {
7
7
  checkJSXText: true,
8
8
  checkStrings: true,
9
9
  checkStringTemplates: true,
10
+ configFile: '',
10
11
  cspell: {
11
12
  words: [],
12
13
  flagWords: [],
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rules = exports.meta = exports.configs = void 0;
4
- const cspell_eslint_plugin_cjs_1 = require("./cspell-eslint-plugin.cjs");
5
- var cspell_eslint_plugin_cjs_2 = require("./cspell-eslint-plugin.cjs");
6
- Object.defineProperty(exports, "configs", { enumerable: true, get: function () { return cspell_eslint_plugin_cjs_2.configs; } });
7
- Object.defineProperty(exports, "meta", { enumerable: true, get: function () { return cspell_eslint_plugin_cjs_2.meta; } });
8
- Object.defineProperty(exports, "rules", { enumerable: true, get: function () { return cspell_eslint_plugin_cjs_2.rules; } });
9
- exports.default = cspell_eslint_plugin_cjs_1.plugin;
3
+ exports.rules = exports.meta = exports.default = exports.configs = void 0;
4
+ var cspell_eslint_plugin_cjs_1 = require("./cspell-eslint-plugin.cjs");
5
+ Object.defineProperty(exports, "configs", { enumerable: true, get: function () { return cspell_eslint_plugin_cjs_1.configs; } });
6
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return cspell_eslint_plugin_cjs_1.plugin; } });
7
+ Object.defineProperty(exports, "meta", { enumerable: true, get: function () { return cspell_eslint_plugin_cjs_1.meta; } });
8
+ Object.defineProperty(exports, "rules", { enumerable: true, get: function () { return cspell_eslint_plugin_cjs_1.rules; } });
10
9
  //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,3 @@
1
1
  export type { Options } from '../common/options.cjs';
2
- import { plugin } from './cspell-eslint-plugin.cjs';
3
- export { configs, meta, rules } from './cspell-eslint-plugin.cjs';
4
- export default plugin;
2
+ export { configs, plugin as default, meta, rules } from './cspell-eslint-plugin.cjs';
5
3
  //# sourceMappingURL=index.d.cts.map
@@ -1,4 +1,4 @@
1
1
  import type { Linter } from 'eslint';
2
2
  export declare const plugins: Record<string, import("eslint").ESLint.Plugin> | undefined;
3
- export declare const rules: Linter.RulesRecord | undefined;
3
+ export declare const rules: Partial<Linter.RulesRecord> | undefined;
4
4
  //# sourceMappingURL=recommended.d.cts.map
@@ -1,7 +1,8 @@
1
- import assert from 'assert';
1
+ // cspell:ignore TSESTree
2
+ import assert from 'node:assert';
3
+ import * as path from 'node:path';
4
+ import { format } from 'node:util';
2
5
  import { createTextDocument, DocumentValidator, extractImportErrors, getDictionary, refreshDictionaryCache, } from 'cspell-lib';
3
- import * as path from 'path';
4
- import { format } from 'util';
5
6
  import { getDefaultLogger } from '../common/logger.cjs';
6
7
  import { walkTree } from './walkTree.mjs';
7
8
  const defaultSettings = {
@@ -311,6 +312,16 @@ function calcInitialSettings(options) {
311
312
  ignoreWords: cspell?.ignoreWords || [],
312
313
  flagWords: cspell?.flagWords || [],
313
314
  };
315
+ if (options.configFile) {
316
+ const optionCspellImport = options.cspell?.import;
317
+ const importConfig = typeof optionCspellImport === 'string'
318
+ ? [optionCspellImport]
319
+ : Array.isArray(optionCspellImport)
320
+ ? optionCspellImport
321
+ : [];
322
+ importConfig.push(options.configFile);
323
+ settings.import = importConfig;
324
+ }
314
325
  if (customWordListFile) {
315
326
  const filePath = isCustomWordListFile(customWordListFile) ? customWordListFile.path : customWordListFile;
316
327
  const { dictionaries = [], dictionaryDefinitions = [] } = settings;
@@ -360,9 +371,9 @@ function normalizeSuggestions(suggestions, nodeType) {
360
371
  if (!isSpecial.test(sug.word))
361
372
  return sug;
362
373
  const s = { ...sug };
363
- s.word = s.word.replace(allSpecial, '_');
374
+ s.word = s.word.replaceAll(allSpecial, '_');
364
375
  if (s.wordAdjustedToMatchCase) {
365
- s.wordAdjustedToMatchCase = s.wordAdjustedToMatchCase.replace(allSpecial, '_');
376
+ s.wordAdjustedToMatchCase = s.wordAdjustedToMatchCase.replaceAll(allSpecial, '_');
366
377
  }
367
378
  return s;
368
379
  });
@@ -376,7 +387,7 @@ function deepEqual(a, b) {
376
387
  assert.deepStrictEqual(a, b);
377
388
  return true;
378
389
  }
379
- catch (e) {
390
+ catch {
380
391
  return false;
381
392
  }
382
393
  }
@@ -1,5 +1,4 @@
1
1
  // @ts-check
2
- /* eslint-disable n/no-missing-import */
3
2
  /**
4
3
  * @typedef {import('estree').Node} Node
5
4
  * @typedef {import('./types.cjs').Issue} Issue
@@ -21,7 +20,6 @@ runAsWorker(
21
20
  */
22
21
  async (filename, text, root, options) => {
23
22
  if (!spellChecker) {
24
- // eslint-disable-next-line import/no-unresolved
25
23
  spellChecker = await import('./spellCheck.mjs');
26
24
  }
27
25
  return spellChecker.spellCheck(filename, text, root, options);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "8.7.0",
6
+ "version": "8.8.1",
7
7
  "description": "CSpell ESLint plugin",
8
8
  "keywords": [
9
9
  "cspell",
@@ -53,9 +53,9 @@
53
53
  "scripts": {
54
54
  "bt": "pnpm build && pnpm test",
55
55
  "build": "pnpm build:schema && pnpm build:src",
56
- "build:src": "tsc -b ./tsconfig.json",
56
+ "build:src": "tsc -b ./tsconfig.json -f",
57
57
  "build:schema": "ts-json-schema-generator --no-top-ref --expose none --path src/common/options.cts --type Options -o ./assets/options.schema.json",
58
- "watch": "tsc -b ./tsconfig.json --watch",
58
+ "watch": "tsc -b ./tsconfig.json --watch -f",
59
59
  "clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
60
60
  "clean-build": "pnpm run clean && pnpm run build",
61
61
  "coverage": "echo coverage",
@@ -75,29 +75,29 @@
75
75
  },
76
76
  "devDependencies": {
77
77
  "@eslint/eslintrc": "^3.0.2",
78
- "@eslint/js": "^9.0.0",
78
+ "@eslint/js": "^9.2.0",
79
79
  "@types/estree": "^1.0.5",
80
80
  "@types/mocha": "^10.0.6",
81
- "@typescript-eslint/parser": "^7.6.0",
82
- "@typescript-eslint/types": "^7.6.0",
83
- "eslint": "^9.0.0",
84
- "eslint-plugin-n": "^17.1.0",
81
+ "@typescript-eslint/parser": "^7.8.0",
82
+ "@typescript-eslint/types": "^7.8.0",
83
+ "eslint": "^9.2.0",
84
+ "eslint-plugin-n": "^17.5.1",
85
85
  "eslint-plugin-react": "^7.34.1",
86
- "eslint-plugin-simple-import-sort": "^12.0.0",
87
- "globals": "^15.0.0",
86
+ "eslint-plugin-simple-import-sort": "^12.1.0",
87
+ "globals": "^15.2.0",
88
88
  "mocha": "^10.4.0",
89
- "ts-json-schema-generator": "^1.5.1",
90
- "typescript": "^5.4.4",
91
- "typescript-eslint": "^7.6.0"
89
+ "ts-json-schema-generator": "^2.1.1",
90
+ "typescript": "^5.4.5",
91
+ "typescript-eslint": "^7.8.0"
92
92
  },
93
93
  "dependencies": {
94
- "@cspell/cspell-types": "8.7.0",
95
- "cspell-lib": "8.7.0",
94
+ "@cspell/cspell-types": "8.8.1",
95
+ "cspell-lib": "8.8.1",
96
96
  "estree-walker": "^3.0.3",
97
97
  "synckit": "^0.9.0"
98
98
  },
99
99
  "peerDependencies": {
100
100
  "eslint": "^7 || ^8 || ^9"
101
101
  },
102
- "gitHead": "5318079ed11fe77e981287ecf1c40d6f28dd91ed"
102
+ "gitHead": "6381846ffce8b9a349bfda03262297aa8e301ef5"
103
103
  }