首先要安装eslint和prettier拓展插件
{
// 是否允许自定义的snippet片段提示
"editor.snippetSuggestions": "top",
"editor.fontSize": 14,
"editor.fontWeight": "400",
"editor.formatOnType": true,
"guides.enabled": false,
"editor.tabSize": 2,
"git.confirmSync": false,
"window.zoomLevel": 0,
"editor.renderWhitespace": "boundary",
"editor.cursorBlinking": "smooth",
"editor.minimap.enabled": true,
"editor.minimap.renderCharacters": false,
"window.title": "${dirty}${activeEditorMedium}${separator}${rootName}",
"editor.codeLens": true,
// 配置文件关联,以便启用对应的提示
"files.associations": {
"*.vue": "vue",
"*.wxss": "css"
},
// 配置emmet是否启用tab展开缩写
"emmet.triggerExpansionOnTab": true,
// 配置emmet对文件类型的支持
"emmet.syntaxProfiles": {
"javascript": "jsx",
"vue": "html",
"vue-html": "html"
},
// 是否开启eslint检测
"eslint.enable": true,
// 文件保存时是否根据eslint进行格式化
"eslint.autoFixOnSave": true,
// eslint配置文件
"eslint.options": {
"extensions": [".js", ".vue"]
},
// eslint能够识别的文件后缀类型
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "vue",
"autoFix": true
},
{
"language": "html",
"autoFix": true
},
"vue",
"html"
],
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true
},
"vetur.format.defaultFormatter.html": "prettier",
// 格式化快捷键(默认):Shift+Alt+F
// prettier进行格式化时,开启eslint支持
"prettier.eslintIntegration": true,
// 是否使用单引号
"prettier.singleQuote": true,
"dart.flutterSdkPath": "/Applications/flutter",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"git.autofetch": true,
"search.followSymlinks": false,
// background相关配置 Start
}
.eslintrc.js
// https://eslint.org/docs/user-guide/configuring
const switcher = require('./ENV') === 'production' ? 'error' : "off"
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
node: true,
es6: true
},
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
"extends": "eslint:recommended",
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {
// allow async-await
'generator-star-spacing': 'off',
"indent": ["error", 2],
"quotes": ["error", "single"],
"semi": ["error", "never"],
// allow debugger during development
"no-console": switcher,
'no-debugger': switcher,
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// tab or enter key warinring
'no-tabs': 0,
'no-mixed-spaces-and-tabs': 1
}
}
基本配置
module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
},
parser: "vue-eslint-parser",
env: {
browser: true,
node: true,
es6: true,
},
rules: {
'no-console': 'off',
}
}