@frefly/cspell-config 0.0.0-stage → 1.0.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 +84 -2
- package/index.js +33 -0
- package/package.json +25 -3
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @frefly/cspell-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
前端 CSpell 共享配置,用于单词拼写检查。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @frefly/cspell-config @cspell/dict-lorem-ipsum@4.0.5 cspell@10.4.1
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
### 使用默认配置
|
|
14
|
+
|
|
15
|
+
#### 步骤一:创建配置文件
|
|
16
|
+
|
|
17
|
+
在项目根目录创建 `cspell.config.js`:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { createConfig } from '@frefly/cspell-config'
|
|
21
|
+
|
|
22
|
+
export default createConfig()
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
#### 步骤二:创建自定义词典
|
|
26
|
+
|
|
27
|
+
在项目根目录创建 `.cspell/custom-words.txt` 文件,用于存放项目自定义词汇(每行一个单词):
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
frefly
|
|
31
|
+
vitepress
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
当 CSpell 遇到未知单词时,可将其添加到此文件中,避免误报。
|
|
35
|
+
|
|
36
|
+
#### 步骤三:添加拼写检查脚本
|
|
37
|
+
|
|
38
|
+
在 `package.json` 中添加:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"scripts": {
|
|
43
|
+
"spellcheck": "cspell lint --dot --gitignore --color --cache --show-suggestions \"src/**/*.{js,ts,vue,json,md}\""
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### 步骤四:运行检查
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm spellcheck
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### 步骤五:配合 IDE 使用
|
|
55
|
+
|
|
56
|
+
安装 VS Code Code Spell Checker 扩展(`streetsidesoftware.code-spell-checker`),实时显示拼写错误。
|
|
57
|
+
|
|
58
|
+
### 添加忽略路径
|
|
59
|
+
|
|
60
|
+
通过 `ignorePaths` 选项忽略不需要检查的文件或目录:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { createConfig } from '@frefly/cspell-config'
|
|
64
|
+
|
|
65
|
+
export default createConfig({
|
|
66
|
+
ignorePaths: ['src/generated/**', '**/*.min.js']
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 默认配置
|
|
71
|
+
|
|
72
|
+
- 引入 `@cspell/dict-lorem-ipsum` 词典
|
|
73
|
+
- 大小写不敏感(`caseSensitive: false`)
|
|
74
|
+
- 自定义词典指向 `.cspell/custom-words.txt`,且开启 `addWords` 自动添加
|
|
75
|
+
- 默认忽略 `node_modules`、`dist`、`.turbo`、`docs`、`__tests__`、`coverage`
|
|
76
|
+
|
|
77
|
+
## API
|
|
78
|
+
|
|
79
|
+
### `createConfig(options?)`
|
|
80
|
+
|
|
81
|
+
创建 CSpell 配置对象。
|
|
82
|
+
|
|
83
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
84
|
+
| ------------- | ---------- | ------ | ------------ |
|
|
85
|
+
| `ignorePaths` | `string[]` | `[]` | 额外忽略路径 |
|
package/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建 CSpell 配置
|
|
3
|
+
* @param {object} [options]
|
|
4
|
+
* @param {string[]} [options.ignorePaths] - 额外的忽略路径
|
|
5
|
+
* @returns {import('cspell').CSpellSettings}
|
|
6
|
+
*/
|
|
7
|
+
export function createConfig(options = {}) {
|
|
8
|
+
const { ignorePaths = [] } = options
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
import: ['@cspell/dict-lorem-ipsum/cspell-ext.json'], // 排除 lorem ipsum 占位文本的拼写误报
|
|
12
|
+
caseSensitive: false,
|
|
13
|
+
dictionaries: ['custom-words'],
|
|
14
|
+
dictionaryDefinitions: [
|
|
15
|
+
{
|
|
16
|
+
name: 'custom-words',
|
|
17
|
+
path: './.cspell/custom-words.txt',
|
|
18
|
+
addWords: true
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
ignorePaths: [
|
|
22
|
+
'**/node_modules/**',
|
|
23
|
+
'**/dist/**',
|
|
24
|
+
'**/.turbo/**',
|
|
25
|
+
'**/docs/**',
|
|
26
|
+
'**/__tests__/**',
|
|
27
|
+
'**/coverage/**',
|
|
28
|
+
...ignorePaths
|
|
29
|
+
] // package.json 中常含非标准拼写
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default createConfig()
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frefly/cspell-config",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "前端 CSpell 共享配置",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@cspell/dict-lorem-ipsum": "4.0.5",
|
|
19
|
+
"cspell": "10.4.1"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22.18.0"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"release": "pnpm publish --no-git-checks"
|
|
27
|
+
}
|
|
6
28
|
}
|