vue-cli構(gòu)建的項目如何手動添加eslint配置
更新時間:2022年04月15日 10:10:37 作者:RyanxChen
這篇文章主要介紹了vue-cli構(gòu)建的項目如何手動添加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",
根目錄下添加檢測配置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'
? }
}添加忽略檢測配置文件.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ī)則說明
1.使用Eslint的時候如果出現(xiàn)未閉合標簽會報紅
如下:
![]()
對于有強迫癥的我來說不能無視,怎么搞定?
首先找到 .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,
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue實現(xiàn)定義一個全局實例Vue.prototype
這篇文章主要介紹了vue實現(xiàn)定義一個全局實例Vue.prototype,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07
vue-resource + json-server模擬數(shù)據(jù)的方法
本篇文章主要介紹了vue-resource + json-server模擬數(shù)據(jù)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11
基于Vue實現(xiàn)HTML轉(zhuǎn)PDF并導(dǎo)出
這篇文章主要為大家介紹了三種方法,可以實現(xiàn)將HTML頁面轉(zhuǎn)為PDF并實現(xiàn)下載。文中的示例代碼講解詳細,感興趣的小伙伴可以學(xué)習(xí)一下2022-04-04
非Vuex實現(xiàn)的登錄狀態(tài)判斷封裝實例代碼
這篇文章主要給大家介紹了關(guān)于非Vuex實現(xiàn)的登錄狀態(tài)判斷封裝的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2022-02-02

