组件规范
1、组件中的属性类型和默认值不要瞎写
bad:
nameList: {
default: Array,
default: {}
},
求求了我真的会谢,这是什么鬼
good:
nameList: {
type: Array,
default: () => []
},
eslint规则
vue/require-prop-types:'1' // 0是不检查
vue/require-default-prop: '1' // 0是不检查
常用代码规范配置
// 禁用未使用过的标签
"no-unused-labels":2,
// 禁止使用var去定义变量
'no-var': 'error',
// 强制使用一致的换行风格(多人项目中很重要,最好整个项目组使用同样的换行风格)
'linebreak-style': ['error', 'unix'],
//禁止使用console
"no-console": 2,
//禁止修改const声明的变量
"no-const-assign": 2,
//函数参数不能重复
"no-dupe-args": 2,
//switch中的case标签不能重复
"no-duplicate-case": 2,
//不能有声明后未被使用的变量或参数
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
//不能有警告备注
"no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],