Skip to content

Commit fc6cc64

Browse files
authored
fix: Support more CSpell settings in eslint plugin (#4700)
1 parent 4db7285 commit fc6cc64

File tree

12 files changed

+227
-88
lines changed

12 files changed

+227
-88
lines changed

integration-tests/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"devDependencies": {
3838
"@cspell/cspell-bundled-dicts": "workspace:*",
3939
"@cspell/dict-de-de": "^3.1.0",
40+
"@types/jest": "^29.5.3",
4041
"@types/shelljs": "^0.8.12",
4142
"cspell": "workspace:*",
4243
"jest": "^29.6.2"

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
"@rollup/plugin-terser": "^0.4.3",
9595
"@rollup/plugin-typescript": "^11.1.2",
9696
"@tsconfig/node16": "^16.1.0",
97-
"@types/jest": "^29.5.3",
9897
"@types/node": "^18.17.1",
9998
"@typescript-eslint/eslint-plugin": "^5.62.0",
10099
"@typescript-eslint/parser": "^5.62.0",
@@ -113,7 +112,6 @@
113112
"eslint-plugin-unicorn": "^48.0.1",
114113
"globcat": "^2.0.1",
115114
"inject-markdown": "^1.5.0",
116-
"jest": "^29.6.2",
117115
"nyc": "^15.1.0",
118116
"prettier": "^3.0.1",
119117
"rollup": "^3.27.1",

packages/cspell-code-snippets/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"node": ">=16"
3131
},
3232
"devDependencies": {
33+
"@types/jest": "^29.5.3",
3334
"jest": "^29.6.2"
3435
}
3536
}

packages/cspell-config-lib/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"yaml": "^1.10.2"
4949
},
5050
"devDependencies": {
51+
"@types/jest": "^29.5.3",
5152
"jest": "^29.6.2"
5253
}
5354
}

packages/cspell-eslint-plugin/assets/options.schema.json

+105
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,125 @@
3737
"additionalProperties": false,
3838
"description": "CSpell options to pass to the spell checker.",
3939
"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+
},
40113
"flagWords": {
41114
"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\" ] ```",
42115
"items": {
43116
"type": "string"
44117
},
45118
"type": "array"
46119
},
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+
},
47128
"ignoreWords": {
48129
"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`.",
49130
"items": {
50131
"type": "string"
51132
},
52133
"type": "array"
53134
},
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+
},
54159
"words": {
55160
"description": "List of words to be considered correct.",
56161
"items": {

packages/cspell-eslint-plugin/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"devDependencies": {
5858
"@types/eslint": "^8.44.1",
5959
"@types/estree": "^1.0.1",
60+
"@types/mocha": "^10.0.1",
6061
"@typescript-eslint/parser": "^5.62.0",
6162
"@typescript-eslint/types": "^6.2.1",
6263
"@typescript-eslint/typescript-estree": "^5.62.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { CSpellSettings } from '@cspell/cspell-types';
2+
import assert from 'assert';
3+
import { describe, test } from 'mocha';
4+
5+
import { defaultOptions, type Options } from './options.js';
6+
7+
describe('options', () => {
8+
test('Options are compatible with cspell-types', () => {
9+
const options: Options = { ...defaultOptions, cspell: { words: ['word'] } };
10+
assert(options.cspell);
11+
const settings: CSpellSettings = options.cspell;
12+
assert(settings, 'it is expected to compile.');
13+
});
14+
});

packages/cspell-eslint-plugin/src/common/options.ts

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CSpellSettings } from '@cspell/cspell-types';
1+
import type { CSpellSettings, DictionaryDefinitionPreferred } from '@cspell/cspell-types';
22

33
export interface Options extends Check {
44
/**
@@ -27,6 +27,25 @@ export interface Options extends Check {
2727
debugMode?: boolean;
2828
}
2929

30+
type DictionaryDefinition = DictionaryDefinitionPreferred;
31+
32+
export type CSpellOptions = Pick<
33+
CSpellSettings,
34+
// | 'languageSettings'
35+
// | 'overrides'
36+
| 'allowCompoundWords'
37+
| 'dictionaries'
38+
| 'enabled'
39+
| 'flagWords'
40+
| 'ignoreWords'
41+
| 'ignoreRegExpList'
42+
| 'includeRegExpList'
43+
| 'import'
44+
| 'words'
45+
> & {
46+
dictionaryDefinition?: DictionaryDefinition;
47+
};
48+
3049
export type RequiredOptions = Required<Options>;
3150

3251
export interface Check {
@@ -76,7 +95,7 @@ export interface Check {
7695
/**
7796
* CSpell options to pass to the spell checker.
7897
*/
79-
cspell?: Pick<CSpellSettings, 'words' | 'ignoreWords' | 'flagWords'>;
98+
cspell?: CSpellOptions;
8099
/**
81100
* Specify a path to a custom word list file.
82101
*
@@ -102,3 +121,9 @@ export interface CustomWordListFile {
102121
}
103122

104123
export type WorkerOptions = RequiredOptions & { cwd: string };
124+
125+
export const defaultOptions: Options = {
126+
numSuggestions: 8,
127+
generateSuggestions: true,
128+
autoFix: false,
129+
};

packages/cspell-eslint-plugin/src/common/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"compilerOptions": {
44
"tsBuildInfoFile": "../../dist/common/compile.tsbuildInfo",
55
"rootDir": ".",
6-
"outDir": "../../dist/common"
6+
"outDir": "../../dist/common",
7+
"skipLibCheck": true
78
},
89
"include": ["."]
910
}

0 commit comments

Comments
 (0)