我用的vscode,eslint好久没更新了,昨天更新了一下,发现个问题,ctrl+s代码不格式化了,看了下文档发现,配置过时了:
文件>首选项>设置搜索eslint>打开settings.json
旧版本格式化:
"eslint.autoFixOnSave": true
新版用这个:
"editor.formatOnSave": true,
全部配置代码:
{
"extensions.ignoreRecommendations": false,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/.vscode": true,
"**/node_modules": true
},
"editor.fontSize": 16,
"vetur.format.defaultFormatter.js": "prettier-eslint",
"vetur.format.defaultFormatter.ts": "vscode-typescript",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"prettier.semi": false,
"prettier.singleQuote": true,
"window.zoomLevel": 0,
"gitlens.advanced.messages": {
"suppressCommitHasNoPreviousCommitWarning": false,
"suppressCommitNotFoundWarning": false,
"suppressFileNotUnderSourceControlWarning": false,
"suppressGitVersionWarning": false,
"suppressLineUncommittedWarning": false,
"suppressNoRepositoryWarning": false,
"suppressResultsExplorerNotice": false,
"suppressShowKeyBindingsNotice": true,
"suppressUpdateNotice": false,
"suppressWelcomeNotice": true
},
"gitlens.keymap": "alternate",
"git.enableSmartCommit": true,
"gitlens.historyExplorer.enabled": true,
"gitlens.views.fileHistory.enabled": true,
"gitlens.views.lineHistory.enabled": true,
//过时了
// "eslint.autoFixOnSave": true,
//新版的自动格式化
"editor.formatOnSave": true,
"svn.enableProposedApi": "product",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.tabSize": 2
}
全部规则代码(.eslintrc文件,没有的话根目录自己建)
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"root": true,
"extends": "standard",
"parser": "babel-eslint",
"plugins": ["html", "vue"],
"rules": {
"semi": "off",
"arrow-parens": 0,
"array-callback-return": 0,
"curly": 1,
"no-void": 0,
"no-eval": 2,
"no-unused-vars": ["warn", { "vars": "local", "args": "none", "ignoreRestSiblings": false }],
"indent": ["error", 2, { "SwitchCase": 1 }],
"eol-last": 0,
"space-before-function-paren": 0,
"no-useless-escape": 0,
"spaced-comment": 0,
"arrow-spacing": 0,
"no-multiple-empty-lines": 0,
"brace-style": "warn",
"quotes": "warn",
"padded-blocks": 0,
"camelcase": "warn"
}
}
别忘了给vscode下载eslint、vetur、Prettier - Code formatter插件
还有项目里package.json开发环境插件
"eslint": "^3.9.1",
"eslint-config-standard": "^6.1.0",
"eslint-friendly-formatter": "^2.0.5",
"eslint-loader": "^1.5.0",
"eslint-plugin-html": "^1.6.0",
"eslint-plugin-promise": "^3.3.0",
"eslint-plugin-standard": "^2.0.1",
"eslint-plugin-vue": "^1.0.0",
对你有帮助的话点个赞哦。