vue-cli構(gòu)建的項(xiàng)目如何手動(dòng)添加eslint配置
package.json里配置添加
1.scripts里添加快捷eslint檢查命令
"lint": "eslint --ext .js,.vue src"
2.添加eslint依賴包
"babel-eslint": "^8.2.1", ? ? "eslint": "^4.15.0", ? ? "eslint-config-standard": "^10.2.1", ? ? "eslint-friendly-formatter": "^3.0.0", ? ? "eslint-loader": "^1.7.1", ? ? "eslint-plugin-import": "^2.7.0", ? ? "eslint-plugin-node": "^5.2.0", ? ? "eslint-plugin-promise": "^3.4.0", ? ? "eslint-plugin-standard": "^3.0.1", ? ? "eslint-plugin-vue": "^4.0.0",
根目錄下添加檢測(cè)配置js文件.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: {
? ? // allow async-await
? ? 'generator-star-spacing': 'off',
? ? // allow debugger during development
? ? 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
? }
}添加忽略檢測(cè)配置文件.eslintignore
/build/
/config/
/dist/
/*.js
webpack.base.conf.js rules里添加eslint-loader配置
const createLintingRule = () => ({
? test: /\.(js|vue)$/,
? loader: 'eslint-loader',
? enforce: 'pre',
? include: [resolve('src'), resolve('test')],
? options: {
? ? formatter: require('eslint-friendly-formatter'),
? ? emitWarning: !config.dev.showEslintErrorsInOverlay
? }
})
module.exports = {
? //.......
? module: {
? ? rules: [
? ? ? ...(config.dev.useEslint ? [createLintingRule()] : []),
? ? //.....config->index.js的dev里添加
useEslint: true, showEslintErrorsInOverlay: false,
Eslint的一些規(guī)則說(shuō)明
1.使用Eslint的時(shí)候如果出現(xiàn)未閉合標(biāo)簽會(huì)報(bào)紅
如下:
![]()
對(duì)于有強(qiáng)迫癥的我來(lái)說(shuō)不能無(wú)視,怎么搞定?
首先找到 .eslintrc.js文件
在 rules 添加以下規(guī)則
"vue/html-self-closing": ["error",{
"html": {
"void": "never",
"normal": "any",
"component": "any"
},
"svg": "always",
"math": "always"
}],保存即可
2.需要在單行元素的內(nèi)容之前和之后換行
![]()
規(guī)則:
"vue/singleline-html-element-content-newline": false,
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
基于vue 動(dòng)態(tài)加載圖片src的解決方法
下面小編就為大家分享一篇基于vue 動(dòng)態(tài)加載圖片src的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
vue實(shí)現(xiàn)定義一個(gè)全局實(shí)例Vue.prototype
這篇文章主要介紹了vue實(shí)現(xiàn)定義一個(gè)全局實(shí)例Vue.prototype,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07
vue-resource + json-server模擬數(shù)據(jù)的方法
本篇文章主要介紹了vue-resource + json-server模擬數(shù)據(jù)的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11
基于Vue實(shí)現(xiàn)HTML轉(zhuǎn)PDF并導(dǎo)出
這篇文章主要為大家介紹了三種方法,可以實(shí)現(xiàn)將HTML頁(yè)面轉(zhuǎn)為PDF并實(shí)現(xiàn)下載。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下2022-04-04
element-ui之解決select無(wú)法回顯的問(wèn)題
這篇文章主要介紹了element-ui之解決select無(wú)法回顯的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
非Vuex實(shí)現(xiàn)的登錄狀態(tài)判斷封裝實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于非Vuex實(shí)現(xiàn)的登錄狀態(tài)判斷封裝的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-02-02

