@cspell/eslint-plugin 7.0.0-alpha.2 → 7.0.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
@@ -15,6 +15,7 @@ This plugin is still in active development as part of the CSpell suite of tools
15
15
  ```
16
16
 
17
17
  - Add to it to `.eslintrc.json`
18
+
18
19
  ```json
19
20
  "extends": ["plugin:@cspell/recommended"]
20
21
  ```
@@ -82,6 +83,17 @@ interface Options {
82
83
  * @default true
83
84
  */
84
85
  checkComments?: boolean;
86
+ /**
87
+ * CSpell settings
88
+ *
89
+ * @words - list of words to be always considered correct
90
+ *
91
+ * @ignoreWords - a list of words to be ignored (even if they are in the flagWords)
92
+ *
93
+ * @flagWords - a list of words to be always considered incorrect, unless ignored.
94
+ *
95
+ */
96
+ cSpell?: { words?: string[]; ignoreWords?: string[]; flagWords?: string[] };
85
97
  /**
86
98
  * Specify a path to a custom word list file.
87
99
  *
@@ -33,6 +33,139 @@
33
33
  "description": "Spell check strings",
34
34
  "type": "boolean"
35
35
  },
36
+ "cspell": {
37
+ "additionalProperties": false,
38
+ "description": "CSpell options to pass to the spell checker.",
39
+ "properties": {
40
+ "allowCompoundWords": {
41
+ "default": false,
42
+ "description": "True to enable compound word checking. See [Case Sensitivity](https://cspell.org/docs/case-sensitive/) for more details.",
43
+ "type": "boolean"
44
+ },
45
+ "dictionaries": {
46
+ "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
+ "items": {
48
+ "description": "Reference to a dictionary by name. One of:\n- {@link DictionaryRef } \n- {@link DictionaryNegRef }",
49
+ "type": "string"
50
+ },
51
+ "type": "array"
52
+ },
53
+ "dictionaryDefinition": {
54
+ "additionalProperties": false,
55
+ "properties": {
56
+ "description": {
57
+ "description": "Optional description.",
58
+ "type": "string"
59
+ },
60
+ "name": {
61
+ "description": "This is the name of a dictionary.\n\nName Format:\n- Must contain at least 1 number or letter.\n- Spaces are allowed.\n- Leading and trailing space will be removed.\n- Names ARE case-sensitive.\n- Must not contain `*`, `!`, `;`, `,`, `{`, `}`, `[`, `]`, `~`.",
62
+ "pattern": "^(?=[^!*,;{}[\\]~\\n]+$)(?=(.*\\w)).+$",
63
+ "type": "string"
64
+ },
65
+ "noSuggest": {
66
+ "description": "Indicate that suggestions should not come from this dictionary. Words in this dictionary are considered correct, but will not be used when making spell correction suggestions.\n\nNote: if a word is suggested by another dictionary, but found in this dictionary, it will be removed from the set of possible suggestions.",
67
+ "type": "boolean"
68
+ },
69
+ "path": {
70
+ "description": "Path to the file.",
71
+ "pattern": "^.*\\.(?:txt|trie)(?:\\.gz)?$",
72
+ "type": "string"
73
+ },
74
+ "repMap": {
75
+ "description": "Replacement pairs.",
76
+ "items": {
77
+ "items": {
78
+ "type": "string"
79
+ },
80
+ "maxItems": 2,
81
+ "minItems": 2,
82
+ "type": "array"
83
+ },
84
+ "type": "array"
85
+ },
86
+ "type": {
87
+ "default": "S",
88
+ "description": "Type of file: S - single word per line, W - each line can contain one or more words separated by space, C - each line is treated like code (Camel Case is allowed). Default is S. C is the slowest to load due to the need to split each line based upon code splitting rules.",
89
+ "enum": [
90
+ "S",
91
+ "W",
92
+ "C",
93
+ "T"
94
+ ],
95
+ "type": "string"
96
+ },
97
+ "useCompounds": {
98
+ "description": "Use Compounds.",
99
+ "type": "boolean"
100
+ }
101
+ },
102
+ "required": [
103
+ "name",
104
+ "path"
105
+ ],
106
+ "type": "object"
107
+ },
108
+ "enabled": {
109
+ "default": true,
110
+ "description": "Is the spell checker enabled.",
111
+ "type": "boolean"
112
+ },
113
+ "flagWords": {
114
+ "description": "List of words to always be considered incorrect. Words found in `flagWords` override `words`.\n\nFormat of `flagWords`\n- single word entry - `word`\n- with suggestions - `word:suggestion` or `word->suggestion, suggestions`\n\nExample: ```ts \"flagWords\": [ \"color: colour\", \"incase: in case, encase\", \"canot->cannot\", \"cancelled->canceled\" ] ```",
115
+ "items": {
116
+ "type": "string"
117
+ },
118
+ "type": "array"
119
+ },
120
+ "ignoreRegExpList": {
121
+ "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).",
122
+ "items": {
123
+ "description": "A PatternRef is a Pattern or PatternId.",
124
+ "type": "string"
125
+ },
126
+ "type": "array"
127
+ },
128
+ "ignoreWords": {
129
+ "description": "List of words to be ignored. An ignored word will not show up as an error, even if it is also in the `flagWords`.",
130
+ "items": {
131
+ "type": "string"
132
+ },
133
+ "type": "array"
134
+ },
135
+ "import": {
136
+ "anyOf": [
137
+ {
138
+ "description": "A File System Path. Relative paths are relative to the configuration file.",
139
+ "type": "string"
140
+ },
141
+ {
142
+ "items": {
143
+ "description": "A File System Path. Relative paths are relative to the configuration file.",
144
+ "type": "string"
145
+ },
146
+ "type": "array"
147
+ }
148
+ ],
149
+ "description": "Allows this configuration to inherit configuration for one or more other files.\n\nSee [Importing / Extending Configuration](https://cspell.org/configuration/imports/) for more details."
150
+ },
151
+ "includeRegExpList": {
152
+ "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).",
153
+ "items": {
154
+ "description": "A PatternRef is a Pattern or PatternId.",
155
+ "type": "string"
156
+ },
157
+ "type": "array"
158
+ },
159
+ "words": {
160
+ "description": "List of words to be considered correct.",
161
+ "items": {
162
+ "type": "string"
163
+ },
164
+ "type": "array"
165
+ }
166
+ },
167
+ "type": "object"
168
+ },
36
169
  "customWordListFile": {
37
170
  "anyOf": [
38
171
  {
@@ -1,3 +1,4 @@
1
+ import type { CSpellSettings, DictionaryDefinitionPreferred } from '@cspell/cspell-types';
1
2
  export interface Options extends Check {
2
3
  /**
3
4
  * Number of spelling suggestions to make.
@@ -21,6 +22,10 @@ export interface Options extends Check {
21
22
  */
22
23
  debugMode?: boolean;
23
24
  }
25
+ type DictionaryDefinition = DictionaryDefinitionPreferred;
26
+ export type CSpellOptions = Pick<CSpellSettings, 'allowCompoundWords' | 'dictionaries' | 'enabled' | 'flagWords' | 'ignoreWords' | 'ignoreRegExpList' | 'includeRegExpList' | 'import' | 'words'> & {
27
+ dictionaryDefinition?: DictionaryDefinition;
28
+ };
24
29
  export type RequiredOptions = Required<Options>;
25
30
  export interface Check {
26
31
  /**
@@ -66,6 +71,10 @@ export interface Check {
66
71
  * @default true
67
72
  */
68
73
  checkComments?: boolean;
74
+ /**
75
+ * CSpell options to pass to the spell checker.
76
+ */
77
+ cspell?: CSpellOptions;
69
78
  /**
70
79
  * Specify a path to a custom word list file.
71
80
  *
@@ -90,4 +99,6 @@ export interface CustomWordListFile {
90
99
  export type WorkerOptions = RequiredOptions & {
91
100
  cwd: string;
92
101
  };
102
+ export declare const defaultOptions: Options;
103
+ export {};
93
104
  //# sourceMappingURL=options.d.ts.map
@@ -1,3 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultOptions = void 0;
4
+ exports.defaultOptions = {
5
+ numSuggestions: 8,
6
+ generateSuggestions: true,
7
+ autoFix: false,
8
+ };
3
9
  //# sourceMappingURL=options.js.map
@@ -7,6 +7,11 @@ exports.defaultCheckOptions = {
7
7
  checkJSXText: true,
8
8
  checkStrings: true,
9
9
  checkStringTemplates: true,
10
+ cspell: {
11
+ words: [],
12
+ flagWords: [],
13
+ ignoreWords: [],
14
+ },
10
15
  customWordListFile: undefined,
11
16
  ignoreImportProperties: true,
12
17
  ignoreImports: true,
@@ -281,29 +281,36 @@ const cache = { lastDoc: undefined };
281
281
  const docValCache = new WeakMap();
282
282
  function getDocValidator(filename, text, options) {
283
283
  const doc = getTextDocument(filename, text);
284
+ const settings = calcInitialSettings(options);
284
285
  const cachedValidator = docValCache.get(doc);
285
- if (cachedValidator) {
286
+ if (cachedValidator && deepEqual(cachedValidator.settings, settings)) {
286
287
  refreshDictionaryCache(0);
287
288
  cachedValidator.updateDocumentText(text);
288
289
  return cachedValidator;
289
290
  }
290
- const settings = calcInitialSettings(options);
291
291
  isDebugMode = options.debugMode || false;
292
292
  const validator = new DocumentValidator(doc, options, settings);
293
293
  docValCache.set(doc, validator);
294
294
  return validator;
295
295
  }
296
296
  function calcInitialSettings(options) {
297
- const { customWordListFile, cwd } = options;
298
- if (!customWordListFile)
299
- return defaultSettings;
300
- const filePath = isCustomWordListFile(customWordListFile) ? customWordListFile.path : customWordListFile;
301
- const dictFile = path.resolve(cwd, filePath);
297
+ const { customWordListFile, cspell, cwd } = options;
302
298
  const settings = {
303
299
  ...defaultSettings,
304
- dictionaryDefinitions: [{ name: 'eslint-plugin-custom-words', path: dictFile }],
305
- dictionaries: ['eslint-plugin-custom-words'],
300
+ words: cspell?.words || [],
301
+ ignoreWords: cspell?.ignoreWords || [],
302
+ flagWords: cspell?.flagWords || [],
306
303
  };
304
+ if (customWordListFile) {
305
+ const filePath = isCustomWordListFile(customWordListFile) ? customWordListFile.path : customWordListFile;
306
+ const dictFile = path.resolve(cwd, filePath);
307
+ const customWordListSettings = {
308
+ ...settings,
309
+ dictionaryDefinitions: [{ name: 'eslint-plugin-custom-words', path: dictFile }],
310
+ dictionaries: ['eslint-plugin-custom-words'],
311
+ };
312
+ return customWordListSettings;
313
+ }
307
314
  return settings;
308
315
  }
309
316
  function getTextDocument(filename, content) {
@@ -338,4 +345,17 @@ function normalizeSuggestions(suggestions, nodeType) {
338
345
  return s;
339
346
  });
340
347
  }
348
+ /**
349
+ * Deep Equal check.
350
+ * Note: There are faster methods, but this is called once per file, so speed is not a concern.
351
+ */
352
+ function deepEqual(a, b) {
353
+ try {
354
+ assert.deepStrictEqual(a, b);
355
+ return true;
356
+ }
357
+ catch (e) {
358
+ return false;
359
+ }
360
+ }
341
361
  //# sourceMappingURL=spellCheck.mjs.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "7.0.0-alpha.2",
6
+ "version": "7.0.0",
7
7
  "description": "CSpell ESLint plugin",
8
8
  "keywords": [
9
9
  "cspell",
@@ -55,20 +55,22 @@
55
55
  "node": ">=16"
56
56
  },
57
57
  "devDependencies": {
58
- "@types/eslint": "^8.37.0",
58
+ "@types/eslint": "^8.44.2",
59
59
  "@types/estree": "^1.0.1",
60
- "@typescript-eslint/parser": "^5.59.2",
61
- "@typescript-eslint/types": "^5.59.2",
62
- "@typescript-eslint/typescript-estree": "^5.59.2",
63
- "eslint": "^8.40.0",
64
- "eslint-plugin-react": "^7.32.2",
60
+ "@types/mocha": "^10.0.1",
61
+ "@typescript-eslint/parser": "^5.62.0",
62
+ "@typescript-eslint/types": "^6.3.0",
63
+ "@typescript-eslint/typescript-estree": "^5.62.0",
64
+ "eslint": "^8.46.0",
65
+ "eslint-plugin-react": "^7.33.1",
65
66
  "mocha": "^10.2.0",
66
67
  "ts-json-schema-generator": "^1.2.0"
67
68
  },
68
69
  "dependencies": {
69
- "cspell-lib": "7.0.0-alpha.2",
70
+ "@cspell/cspell-types": "7.0.0",
71
+ "cspell-lib": "7.0.0",
70
72
  "estree-walker": "^3.0.3",
71
73
  "synckit": "^0.8.5"
72
74
  },
73
- "gitHead": "a1b7c5daeef5afdb14d6444318f450b9fd9c035a"
75
+ "gitHead": "52960d5ed75655978f9b633f44fd106937a63cd7"
74
76
  }