(一) 使用eslint作为代码检查工具
(1) npm 初始化
npm init -y
(2) 安装eslint
npm i eslint -D
(3)安装好以后在package.json里面输入
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"create": "eslint --init"
},
(4)然后敲
npm run create
(5)按照步骤一步步安装你喜欢的配置文件
(6)备注要是服务器端的话eslint禁止使用console.log所以还需要加入句规则
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2016,
"sourceType": "module"
},
"rules": {
'no-console': "off",
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
}
};
网友评论