@@ -18,18 +18,19 @@ npm install prettier
18
18
19
19
### 2、安装 Vscode 插件(Prettier):
20
20
21
- ![ prettier ] ( https://iamge-1259297738.cos.ap-chengdu.myqcloud.com/img/20220510134626 .png )
21
+ ![ Prettier ] ( https://iamge-1259297738.cos.ap-chengdu.myqcloud.com/md/Prettier .png )
22
22
23
23
### 3、配置 Prettier:
24
24
25
25
``` javascript
26
- // https://www.prettier.cn
26
+ // @see: https://www.prettier.cn
27
+
27
28
module .exports = {
28
29
// 超过最大值换行
29
30
printWidth: 130 ,
30
31
// 缩进字节数
31
32
tabWidth: 2 ,
32
- // 使用制表符而不是空格缩进行(true代表table,false代表space)
33
+ // 使用制表符而不是空格缩进行
33
34
useTabs: true ,
34
35
// 结尾不用分号(true有,false没有)
35
36
semi: true ,
@@ -61,6 +62,7 @@ module.exports = {
61
62
// Vue文件脚本和样式标签缩进
62
63
vueIndentScriptAndStyle: false
63
64
};
65
+
64
66
```
65
67
66
68
@@ -86,15 +88,17 @@ npm install eslint eslint-config-prettier eslint-plugin-prettier eslint-plugin-v
86
88
87
89
- ** ESLint:**
88
90
89
- ![ eslint ] ( https://iamge-1259297738.cos.ap-chengdu.myqcloud.com/img/20220510135758 .png )
91
+ ![ ESLint ] ( https://iamge-1259297738.cos.ap-chengdu.myqcloud.com/md/ESLint .png )
90
92
91
93
- ** TSLint:**
92
94
93
- ![ tslint ] ( https://iamge-1259297738.cos.ap-chengdu.myqcloud.com/img/20220510140124 .png )
95
+ ![ TSLint ] ( https://iamge-1259297738.cos.ap-chengdu.myqcloud.com/md/TSLint .png )
94
96
95
97
### 3、配置 ESLint:
96
98
97
99
``` javascript
100
+ // @see: http://eslint.cn
101
+
98
102
module .exports = {
99
103
root: true ,
100
104
env: {
@@ -160,13 +164,181 @@ module.exports = {
160
164
" vue/multi-word-component-names" : " off" // 要求组件名称始终为 “-” 链接的单词
161
165
}
162
166
};
167
+
163
168
```
164
169
165
170
166
171
167
172
## 四、样式规范工具(StyleLint)
168
173
169
- > ……后面补充
174
+ ### 1、安装 StyleLint 相关插件:
175
+
176
+ ``` text
177
+ npm i stylelint stylelint-config-html stylelint-config-recommended-scss stylelint-config-recommended-vue stylelint-config-standard stylelint-config-standard-scss stylelint-order postcss postcss-html stylelint-config-prettier -D
178
+ ```
179
+
180
+ | 依赖 | 作用描述 |
181
+ | :-------------------------------: | :----------------------------------------------------------: |
182
+ | stylelint | stylelint 核心库 |
183
+ | stylelint-config-html | Stylelint 的可共享 HTML(和类似 HTML)配置,捆绑 postcss-html 并对其进行配置。 |
184
+ | stylelint-config-recommended-scss | 扩展 stylelint-config-recommended 共享配置,并为 SCSS 配置其规则 |
185
+ | stylelint-config-recommended-vue | 扩展 stylelint-config-recommended 共享配置,并为 Vue 配置其规则 |
186
+ | stylelint-config-standard | 打开额外的规则来执行在规范和一些 CSS 样式指南中发现的通用约定,包括:惯用 CSS 原则,谷歌的 CSS 样式指南,Airbnb 的样式指南,和 @mdo 的代码指南。 |
187
+ | stylelint-config-standard-scss | 扩展 stylelint-config-standard 共享配置,并为 SCSS 配置其规则 |
188
+ | postcss | postcss-html 的依赖包 |
189
+ | postcss-html | 用于解析 HTML(和类似 HTML)的 PostCSS 语法 |
190
+ | stylelint-order | 属性的排序(插件包) |
191
+ | stylelint-config-prettier | 关闭所有不必要的或可能与 Prettier 冲突的规则 |
192
+
193
+ ### 2、安装 Vscode 插件(Stylelint):
194
+
195
+ ![ Stylelint] ( https://iamge-1259297738.cos.ap-chengdu.myqcloud.com/md/Stylelint.png )
196
+
197
+ ### 3、在目录的 .vscode 文件中新建 settings.json:
198
+
199
+ ``` json
200
+ {
201
+ "stylelint.enable" : true ,
202
+ "editor.codeActionsOnSave" : {
203
+ "source.fixAll.stylelint" : true
204
+ },
205
+ "stylelint.validate" : [" css" , " less" , " postcss" , " scss" , " vue" , " sass" ," html" ]
206
+ }
207
+ ```
208
+
209
+ > 😎也可以在vscode中全局配置上述json代码😎
210
+
211
+
212
+
213
+ ### 4、配置 stylelint.config.js
214
+
215
+ ```` javascript
216
+ // @see: https://stylelint.io
217
+
218
+ module .exports = {
219
+ /* 继承某些已有的规则 */
220
+ extends: [
221
+ " stylelint-config-standard" ,
222
+ " stylelint-config-html/vue" ,
223
+ " stylelint-config-standard-scss" ,
224
+ " stylelint-config-recommended-vue/scss" ,
225
+ " stylelint-config-prettier"
226
+ ],
227
+ /* 使用排序插件 */
228
+ plugins: [" stylelint-order" ],
229
+ overrides: [
230
+ // 扫描 .vue/html 文件中的<style>标签内的样式
231
+ {
232
+ files: [" **/*.{vue,html}" ],
233
+ customSyntax: " postcss-html"
234
+ }
235
+ ],
236
+ /**
237
+ * null => 关闭该规则
238
+ */
239
+ rules: {
240
+ indentation: null , // 指定缩进空格
241
+ " no-descending-specificity" : null , // 禁止在具有较高优先级的选择器后出现被其覆盖的较低优先级的选择器
242
+ " function-url-quotes" : " always" , // 要求或禁止 URL 的引号 "always(必须加上引号)"|"never(没有引号)"
243
+ " string-quotes" : " double" , // 指定字符串使用单引号或双引号
244
+ " unit-case" : null , // 指定单位的大小写 "lower(全小写)"|"upper(全大写)"
245
+ " color-hex-case" : " lower" , // 指定 16 进制颜色的大小写 "lower(全小写)"|"upper(全大写)"
246
+ " color-hex-length" : " long" , // 指定 16 进制颜色的简写或扩写 "short(16进制简写)"|"long(16进制扩写)"
247
+ " rule-empty-line-before" : " never" , // 要求或禁止在规则之前的空行 "always(规则之前必须始终有一个空行)"|"never(规则前绝不能有空行)"|"always-multi-line(多行规则之前必须始终有一个空行)"|"never-multi-line(多行规则之前绝不能有空行。)"
248
+ " font-family-no-missing-generic-family-keyword" : null , // 禁止在字体族名称列表中缺少通用字体族关键字
249
+ " block-opening-brace-space-before" : " always" , // 要求在块的开大括号之前必须有一个空格或不能有空白符 "always(大括号前必须始终有一个空格)"|"never(左大括号之前绝不能有空格)"|"always-single-line(在单行块中的左大括号之前必须始终有一个空格)"|"never-single-line(在单行块中的左大括号之前绝不能有空格)"|"always-multi-line(在多行块中,左大括号之前必须始终有一个空格)"|"never-multi-line(多行块中的左大括号之前绝不能有空格)"
250
+ " property-no-unknown" : null , // 禁止未知的属性(true 为不允许)
251
+ " no-empty-source" : null , // 禁止空源码
252
+ " declaration-block-trailing-semicolon" : null , // 要求或不允许在声明块中使用尾随分号 string:"always(必须始终有一个尾随分号)"|"never(不得有尾随分号)"
253
+ " selector-pseudo-class-no-unknown" : [
254
+ true ,
255
+ {
256
+ ignorePseudoClasses: [" deep" ]
257
+ }
258
+ ],
259
+ // 样式的排序规则
260
+ " order/properties-order" : [
261
+ " position" ,
262
+ " top" ,
263
+ " right" ,
264
+ " bottom" ,
265
+ " left" ,
266
+ " z-index" ,
267
+ " display" ,
268
+ " justify-content" ,
269
+ " align-items" ,
270
+ " float" ,
271
+ " clear" ,
272
+ " overflow" ,
273
+ " overflow-x" ,
274
+ " overflow-y" ,
275
+ " margin" ,
276
+ " margin-top" ,
277
+ " margin-right" ,
278
+ " margin-bottom" ,
279
+ " margin-left" ,
280
+ " padding" ,
281
+ " padding-top" ,
282
+ " padding-right" ,
283
+ " padding-bottom" ,
284
+ " padding-left" ,
285
+ " width" ,
286
+ " min-width" ,
287
+ " max-width" ,
288
+ " height" ,
289
+ " min-height" ,
290
+ " max-height" ,
291
+ " font-size" ,
292
+ " font-family" ,
293
+ " font-weight" ,
294
+ " border" ,
295
+ " border-style" ,
296
+ " border-width" ,
297
+ " border-color" ,
298
+ " border-top" ,
299
+ " border-top-style" ,
300
+ " border-top-width" ,
301
+ " border-top-color" ,
302
+ " border-right" ,
303
+ " border-right-style" ,
304
+ " border-right-width" ,
305
+ " border-right-color" ,
306
+ " border-bottom" ,
307
+ " border-bottom-style" ,
308
+ " border-bottom-width" ,
309
+ " border-bottom-color" ,
310
+ " border-left" ,
311
+ " border-left-style" ,
312
+ " border-left-width" ,
313
+ " border-left-color" ,
314
+ " border-radius" ,
315
+ " text-align" ,
316
+ " text-justify" ,
317
+ " text-indent" ,
318
+ " text-overflow" ,
319
+ " text-decoration" ,
320
+ " white-space" ,
321
+ " color" ,
322
+ " background" ,
323
+ " background-position" ,
324
+ " background-repeat" ,
325
+ " background-size" ,
326
+ " background-color" ,
327
+ " background-clip" ,
328
+ " opacity" ,
329
+ " filter" ,
330
+ " list-style" ,
331
+ " outline" ,
332
+ " visibility" ,
333
+ " box-shadow" ,
334
+ " text-shadow" ,
335
+ " resize" ,
336
+ " transition"
337
+ ]
338
+ }
339
+ };
340
+
341
+ ````
170
342
171
343
172
344
@@ -227,6 +399,7 @@ npm install husky -D
227
399
228
400
```` text
229
401
# 编辑 package.json > prepare 脚本并运行一次
402
+
230
403
npm set-script prepare "husky install"
231
404
npm run prepare
232
405
````
@@ -253,9 +426,12 @@ npx husky add .husky/pre-commit "npm run lint:lint-staged"
253
426
254
427
```` text
255
428
module.exports = {
429
+ "*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"],
256
430
"{!(package)*.json,*.code-snippets,.!(browserslist)*rc}": ["prettier --write--parser json"],
257
- "*.{scss,less,css,html,md},package.json": ["prettier --write"],
258
- "*.{js,jsx,ts,tsx,vue}": ["prettier --write", "eslint --fix"]
431
+ "package.json": ["prettier --write"],
432
+ "*.vue": ["eslint --fix", "prettier --write", "stylelint --fix"],
433
+ "*.{scss,less,styl,html}": ["stylelint --fix", "prettier --write"],
434
+ "*.md": ["prettier --write"]
259
435
};
260
436
````
261
437
@@ -266,7 +442,7 @@ module.exports = {
266
442
> ** 安装:**
267
443
268
444
```` text
269
- // commitlint && @commitlint/cli 其中一个都行
445
+ // commitlint && @commitlint/cli 其中一个插件都行
270
446
npm i commitlint @commitlint/config-conventional -D
271
447
npm i @commitlint/cli @commitlint/config-conventional -D
272
448
````
@@ -309,7 +485,7 @@ npm install cz-git -D
309
485
> ** 新建 commitlint.config.js 文件:**
310
486
311
487
```` javascript
312
- // @see: https://cz-git.qbenben.com/zh/guide/
488
+ // @see: https://cz-git.qbenben.com/zh/guide
313
489
/** @type {import('cz-git').UserConfig} */
314
490
315
491
module .exports = {
@@ -437,7 +613,7 @@ module.exports = {
437
613
// { value: "回退", name: "回退: ⏪️ 回滚 commit", emoji: ":rewind:" },
438
614
// { value: "其他", name: "其他: 🔨 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)", emoji: ":hammer:" }
439
615
],
440
- useEmoji: true ,
616
+ useEmoji: false ,
441
617
themeColorCode: " " ,
442
618
scopes: [],
443
619
allowCustomScopes: true ,
0 commit comments