让vscode按照eslint进行格式化
Posted superclound
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了让vscode按照eslint进行格式化相关的知识,希望对你有一定的参考价值。
1.安装eslint依赖
在package.json中用npm安装eslint的依赖
"eslint": "^4.19.1",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.0.0",
"eslint-plugin-html": "^4.0.3",
2.生成eslint配置文件
在项目根目录下建立 .eslintrc.js
文件,复制下面的内容到里面
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
// 在js里面有些时候用到一些全局变量,防止eslint无脑报错
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"process": false
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"linebreak-style": [
"error",
"unix"
],
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"array-bracket-spacing": [2, "never"],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"camelcase": [2, { "properties": "never" }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$"],
"indent": [2, 2, { "SwitchCase": 1 }],
"jsx-quotes": [2, "prefer-single"],
"key-spacing": [2, { "beforeColon": false, "afterColon":