ESLint 安装使用及报错处理

发布时间 2023-06-28 16:06:25作者: 一名小学生呀

安装 ESlint 并初始化配置

// 第一种
// 全局安装 ESLint
npm i eslint -g

// 生成配置文件
// 根据自己的项目需求进行设置(yes/no)
eslint --init

√ How would you like to use ESLint · problems
√ What type of modules does your project use · esm
√ Which framework does your project use · vue
√ Does your project use TypeScript · No / Yes
√ Where does your code run · browser
√ What format do you want your config file to be in · JavaScript
The config that you’ve selected requires the following dependencies:

// 第二种
// 在项目中安装 ESLint
npm install eslint --save-dev


// 生成配置文件
// 初始化成功后,会在项目根目录生成 .eslintrc.js 文件
./node_modules/.bin/eslint --init

module.exports = {
“env”: {
“browser”: true,
“es2021”: true
},
“extends”: [
“eslint:recommended”,
“plugin:vue/essential”
],
“parserOptions”: {
“ecmaVersion”: 12,
“sourceType”: “module”
},
“plugins”: [
“vue”
],
“rules”: {
}
};

 

eslint-plugin-standard 版本不兼容问题

将 eslint-config-standard 版本进行降级为 ^14.1.1
删除 .eslintrc.js 中 "env" 中的 "es2021" 属性

 

eslint 的 webpack打包错误

// eslint 配置 babel-eslint 插件
npm install babel-eslint --save

// package.json中配置 eslintConfig 属性
"eslintConfig":{
    "parser":"babel-eslint"
}