一、eslint配置文件名写法
错误:ERROR in [eslint] Could not find config file. 的意思是找不到eslint配置文件,
eslint 9.0以上的版本已经废弃了.eslintrc.js 的写法,所以要配置文件要写成 eslint.config.js
二、旧版eslint基本配置写法
module.exports = {
// 继承Eslint内置规则
extends: ["eslint:recommended"],
env: {
node: true, // 启用node中的全局变量
browser: true, // 启用浏览器中的全局变量
},
// 解析选项
parserOptions: {
ecmaVersion: 6, // es6
sourceType: "module", // es module
},
// 规则
rules: {
"no-var": 2, // 不能使用var定义变量
}
}
三、新版的eslint基本配置写法
9.0以上版本eslint中没有了可以被继承的检查规则,移到了 @eslint/js 包中
引入的包如何下载:
npm i -D eslint @eslint/js
globals不用下载,反正我没下他也没报错,如果你们报错了就下一下吧
const {defineConfig, globalIgnores} = require("eslint/config")
const js = require("@eslint/js")
const globals = require("globals")
module.exports = defineConfig([
// 全局忽略
globalIgnores(["dist/"]),
{
// 检查哪些文件
files: ["src/**/*.js"],
// 局部忽略哪些文件不检查
ignores: ["dist/"],
// 应用插件
plugins:{
js
},
// 继承检查规则
extends: ["js/recommended"],
// 语言选项
languageOptions:{
ecmaVersion: 6, // 检查es6版本
sourceType: "module", // 检查的文件类型,这里是检查模块化文件
globals: {
...globals.browser, // 启用浏览器中的全局变量
...globals.node // 启用node中的全局变量
}
},
// 自己写的规则,如果和继承的规则重复会将其覆盖
rules: {
// 不能使用var,0:关闭规则(off);1:警告(warn);2:报错(error)
"no-var": "error",
}
}
])