This repository was archived by the owner on Aug 11, 2021. It is now read-only.
File tree 2 files changed +48
-2
lines changed
2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ module.exports = {
6
6
} ,
7
7
globals : {
8
8
process : true ,
9
- require : true
9
+ require : true ,
10
+ module : true
10
11
} ,
11
12
extends : [
12
13
'plugin:vue/strongly-recommended' ,
Original file line number Diff line number Diff line change 29
29
30
30
> 可通过修改 ` .eslintignore ` 和 ` .stylelintignore ` 忽略无需做代码规范的文件,例如在项目中引用了一些第三方的插件或组件,我们就可以将其忽略
31
31
32
- 如果 ` git init ` 仓库初始化是在依赖包安装之后执行的,则无法初始化 Git 钩子,建议在 ` git init ` 之后再执行一遍 ` yarn ` 或者 ` npm i ` ,重新安装一遍依赖包。
32
+ 如果 ` git init ` 仓库初始化是在依赖包安装之后执行的,则无法初始化 Git 钩子,建议在 ` git init ` 之后再执行一遍 ` yarn ` 或者 ` npm i ` ,重新安装一遍依赖包。
33
+
34
+ ## 配置代码规范
35
+
36
+ 配置文件主要有 3 处,分别为 IDE 配置(` .editorconfig ` )、ESLint 配置(` .eslintrc.js ` 和 ` .eslintignore ` )、StyleLint 配置(` .stylelintrc ` 和 ` .stylelintignore ` )。
37
+
38
+ 已代码缩进举例,模版默认是以 4 空格为缩进,如果要调整为 2 空格,则分别在 ` .editorconfig ` 里修改:
39
+
40
+ ```
41
+ indent_size = 2
42
+ ```
43
+
44
+ 在 ` .eslintrc.js ` 里修改:
45
+
46
+ ```
47
+ 'indent': [2, 2, {
48
+ 'SwitchCase': 1
49
+ }],
50
+
51
+ ...
52
+
53
+ 'vue/html-indent': [2, 2],
54
+
55
+ ...
56
+
57
+ 'vue/script-indent': [2, 2, {
58
+ 'switchCase': 1
59
+ }]
60
+ ```
61
+
62
+ 在 ` .stylelintrc ` 里修改:
63
+
64
+ ```
65
+ "indentation": 2
66
+ ```
67
+
68
+ 修改完毕后,分别执行:
69
+
70
+ ``` bash
71
+ yarn run lint
72
+ yarn run stylelint
73
+ ```
74
+
75
+ 该操作会将代码进行一次格式校验,如果规则支持自动修复,则会将不符合规则的代码自动进行格式化。
76
+
77
+ 以上面的例子,当缩进规则调整后,我们无需手动去每个文件调整,通过命令可以自动应用新的缩进规则。
You can’t perform that action at this time.
0 commit comments