vscode+eslint+vue+html+css 一步到位

目的:在用vscode編輯vue和html文件時,用eslint可以同時驗證其中的js代碼,讓其符合js standard和vue的規(guī)則。

===安裝eslint支持,都安裝在項目中===

cmd進(jìn)入項目目錄

npm init -y

npm i -D eslint

npm i -D eslint-plugin-vue

npm i -D eslint-plugin-html

npm i -D eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node

===vscode安裝插件===

vetur,eslint, IntelliSense for CSS class names,css peek

#ctrl+shift+p

#然后eslint c,在當(dāng)前項目中創(chuàng)建.eslintrc.json文件。

#或者開啟optinons選項來引用異地的配置文件

#.eslintrc.json中必須用"html/html-extensions": [".html", ".we"],來限定eslint-plugin-html的作用范圍,因為eslint-plugin-html與eslint-plugin-vue有沖突,不限定的話會導(dǎo)致eslint無法識別錯誤

#同時啟用了兩個js驗證規(guī)則:standard, eslint-plugin-vue

===.eslintrc.json===

{

? ? "env": {

? ? ? ? "browser": true,

? ? ? ? "commonjs": true,

? ? ? ? "es6": true,

? ? ? ? "node": true

? ? },

? ? "parserOptions": {

? ? ? ? "ecmaFeatures": {

? ? ? ? ? ? "jsx": true

? ? ? ? },

? ? ? ? "sourceType": "module"

? ? },

? ? "plugins": [ "html" ],

? ? "settings": {

? ? ? ? "html/html-extensions": [".html", ".we"],

? ? ? ? "html/report-bad-indent": "error"

? ? },

? ? "extends": [

? ? ? ? "standard",

? ? ? ? "plugin:vue/recommended"

? ? ],? ?

? ? "rules": {

? ? ? ? "no-const-assign": "warn",

? ? ? ? "no-this-before-super": "warn",

? ? ? ? "no-undef": "warn",

? ? ? ? "no-unreachable": "warn",

? ? ? ? "no-unused-vars": "warn",

? ? ? ? "constructor-super": "warn",

? ? ? ? "valid-typeof": "warn"

? ? }

}

===vscode自定義配置===

{

? ? "git.ignoreMissingGitWarning": true,

? ? "workbench.startupEditor": "newUntitledFile",

? ? "editor.fontSize": 16,

? ? "javascript.validate.enable": false,

? ? "files.exclude": {

? ? ? ? "**/.git": true,

? ? ? ? "**/.svn": true,

? ? ? ? "**/.hg": true,

? ? ? ? "**/CVS": true,

? ? ? ? "**/.DS_Store": true,

? ? ? ? "**/node_modules": true

? ? ? },

? ? //不增加關(guān)聯(lián),eslint-plugin-vue會產(chǎn)生重復(fù)提示

? ? "files.associations": {

? ? ? ? "*.vue": "html"

? ? },

? ? "eslint.options": {

? ? ? ? //"configFile": "F:/.eslintrc.json"

? ? },

? ? "eslint.validate": [

? ? ? ? "javascript",

? ? ? ? "javascriptreact",

? ? ? ? "html",

? ? ? ? "vue"

? ? ],

}

===刪除vscode時要清理的目錄===

C:\\Users\\ZR\AppData\\Roaming\\Code

C:\\Users\\ZR\\.vscode

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容