Skip to content

eslint

给代码的 window 上添加全局变量

比如,你的 window 对象上实际挂载了 BUL 属性,你可以通过 window.BUL 点语法访问,但 eslint 却报错说 BUL 不在 window 上。

这时候,你可以设置 .eslintrc 文件:

json
{
  "env": {
      "browser": true,
      "es2021": true
  },
  "root": true,
  "globals": {
      "BUL": "readonly"
  }
}

给项目配置 eslint

只需要执行下面的命令,再根据提示选择相应的配置就行了。

shell
npm init @eslint/config

eslint 检查单一的文件或目录

执行命令 npm init @eslint/config 配置好 eslint 后,如果你想检查单一的文件或目录,可以执行像下面这样的命令:

shell
npx eslint yourfile.js
npx eslint project-dir/ file1.js
yarn run eslint yourfile.js

Released under the MIT License.