vue-cli構建的項目如何手動添加eslint配置
更新時間:2022年04月15日 10:10:37 作者:RyanxChen
這篇文章主要介紹了vue-cli構建的項目如何手動添加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.需要在單行元素的內容之前和之后換行
![]()
規(guī)則:
"vue/singleline-html-element-content-newline": false,
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue+VeeValidate 校驗范圍實例詳解(部分校驗,全部校驗)
validate()可以指定校驗范圍內,或者是全局的 字段。而validateAll()只能校驗全局。這篇文章主要介紹了vue+VeeValidate 校驗范圍(部分校驗,全部校驗) ,需要的朋友可以參考下2018-10-10
Vue突然報錯doesn‘t?work?properly?without?JavaScript?enabled
最近在做項目的時候遇到了些問題,所以這篇文章主要給大家介紹了關于Vue突然報錯doesn‘t?work?properly?without?JavaScript?enabled的解決方法,需要的朋友可以參考下2023-01-01

