解決縮進(jìn)報錯問題常用設(shè)置:
1.文件->首選項(xiàng)->設(shè)置->擴(kuò)展->eslint->在settings.json中編輯:
"eslint.codeAction.disableRuleComment":?{
????//?vscode默認(rèn)啟用了根據(jù)文件類型自動設(shè)置tabsize的選項(xiàng)
????"editor.detectIndentation":?false,
????//?重新設(shè)定tabsize
????"editor.tabSize":?2,
????//?#每次保存的時候自動格式化
????"editor.formatOnSave":?true,
????//?#每次保存的時候?qū)⒋a按eslint格式進(jìn)行修復(fù)
????"eslint.autoFixOnSave":?true,
????//?添加?vue?支持
????"eslint.validate":?[
??????"javascript",
??????"javascriptreact",
??????{
????????"language":?"vue",
????????"autoFix":?true
??????}
????],
????//??#讓prettier使用eslint的代碼格式進(jìn)行校驗(yàn)
????"prettier.eslintIntegration":?true,
????//??#去掉代碼結(jié)尾的分號
????"prettier.semi":?false,
????//??#使用帶引號替代雙引號
????"prettier.singleQuote":?true,
????//??#讓函數(shù)(名)和后面的括號之間加個空格
????"javascript.format.insertSpaceBeforeFunctionParenthesis":?true,
????//?#這個按用戶自身習(xí)慣選擇
????"vetur.format.defaultFormatter.html":?"js-beautify-html",
????//?#讓vue中的js按編輯器自帶的ts格式進(jìn)行格式化
????"vetur.format.defaultFormatter.js":?"vscode-typescript",
????"vetur.format.defaultFormatterOptions":?{
??????"js-beautify-html":?{
????????"wrap_attributes":?"force-aligned"
????????//?#vue組件中html代碼格式化樣式
??????}
????},
????//?格式化stylus,?需安裝Manta's?Stylus?Supremacy插件
????"stylusSupremacy.insertColons":?false,?//?是否插入冒號
????"stylusSupremacy.insertSemicolons":?false,?//?是否插入分好
????"stylusSupremacy.insertBraces":?false,?//?是否插入大括號
????"stylusSupremacy.insertNewLineAroundImports":?false,?//?import之后是否換行
????"stylusSupremacy.insertNewLineAroundBlocks":?false,
????"editor.suggestSelection":?"first",
????"vsintellicode.modify.editor.suggestSelection":?"automaticallyOverrodeDefaultValue"?//?兩個選擇器中是否換行
??},
2.配置?.eslintrc.js?規(guī)則:
module.exports?=?{
????root:?true,
????env:?{
????????node:?true
????},
????extends:?[
????????'plugin:vue/essential',
????????'@vue/standard'
????],
????parserOptions:?{
????????parser:?'babel-eslint'
????},
????rules:?{
????????'no-console':?process.env.NODE_ENV?===?'production'???'warn'?:?'off',
????????'no-debugger':?process.env.NODE_ENV?===?'production'???'warn'?:?'off',
????????//?allow?async-await
????????'generator-star-spacing':?'off',
????????//?allow?debugger?during?development
????????'no-debugger':?process.env.NODE_ENV?===?'production'???'error'?:?'off',
????????/*
???0?或’off’:??關(guān)閉規(guī)則臭挽。
???1?或’warn’:?打開規(guī)則,并且作為一個警告,字體顏色為黃色(并不會導(dǎo)致檢查不通過)坛梁。
???2?或’error’:打開規(guī)則,并且作為一個錯誤?腊凶,色體顏色為紅色(退出碼為1划咐,檢查不通過)。
??????*/
????????//?以下為該項(xiàng)目自定義部分
????????'indent':?[2,?4],?//縮進(jìn)風(fēng)格?-?開啟縮進(jìn)4格
????????'no-spaced-func':?2,?//函數(shù)調(diào)用時?函數(shù)名與()之間不能有空格?-?開啟
????????'no-const-assign':?2,?//禁止修改const聲明的變量?-?開啟
????????'space-before-function-paren':?[0,?'always'],?//函數(shù)定義時括號前面要有空格?-?關(guān)閉
????????'eol-last':?0,?//文件以單一的換行符結(jié)束?-?關(guān)閉
????????'camelcase':?0,?//強(qiáng)制駝峰法命名?-?關(guān)閉
????????'no-undef':?0,?//不能有未定義的變量?-?關(guān)閉
????????'no-alert':?0,?//禁止使用alert?confirm?prompt?-?關(guān)閉
????????'arrow-parens':?0,?//箭頭函數(shù)用小括號括起來?-?關(guān)閉
????}
}
3.配置.editorconfig規(guī)則:
[*.{js,jsx,ts,tsx,vue}]
indent_style?=?space
indent_size?=?2
trim_trailing_whitespace?=?true
insert_final_newline?=?true
root?=?true?//?讓這個文件生效
[*]?//?對所有文件都生效
charset?=?utf-8?//?編碼
indent_style?=?space?//?縮進(jìn)'tabs鍵',如果習(xí)慣用空格可以設(shè)為'space'
indent_size?=?2?//?縮進(jìn)的尺寸
end_of_line?=?lf?//?換行符格式(開發(fā)系統(tǒng)差異)
insert_final_newline?=?true?//?是否在文件的最后插入一個空行
trim_trailing_whitespace?=?true?//?是否刪除行尾的空格
配置完成后解決問題: