1. 安裝vscode插件
- ESLint
- Prettier formatter for Visual Studio Code
- Vetur
2. 配置文件
.editorconfig
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
tab_width = 1
.eslintrc.js
// https://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint'
},
env: {
browser: true,
},
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard'
],
// required to lint *.vue files
plugins: [
'vue'
],
// add your custom rules here
rules: {
// 融合了 jquery 所以暫時屏蔽
"no-undef": 0, //不允許未聲明的變量
"no-unused-vars": [0, {"vars": "all", "args": "after-used"}], //不允許有聲明后未使用的變量或者參數(shù)
"no-tabs": 0, //不允許tabs
"no-mixed-spaces-and-tabs": [0, "smart-tabs"], //不允許混用tab和空格
"indent": [0, 4],//縮進風(fēng)格
"camelcase": [0, {"properties": "never"}], //強制駝峰命名規(guī)則
"space-before-function-paren": [0, {"anonymous": "always", "named": "never"}], //函數(shù)定義時括號前的空格
// allow paren-less arrow functions
'arrow-parens': 0,
'no-extra-semi': 0, //不允許出現(xiàn)不必要的分號
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
}
用戶設(shè)置 setting.json
{
"files.autoSave": "afterDelay",
"editor.fontSize": 14,
"editor.tabSize": 2,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
{
"language": "html",
"autoFix": true
}
],
"prettier.singleQuote": true,
"prettier.semi": false
}
3. 使用
- 方式一:右鍵格式化代碼
- 方式二:打開命令面板 (>eslint fix all auto-fixable problems)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者