配置语言选项
JavaScript 生态系统具有多种运行时、版本、扩展和框架。其中每一个都可以有不同的支持语法和全局变量。ESLint 允许您配置特定于项目中使用的 JavaScript 的语言选项,例如自定义全局变量。您还可以使用插件来扩展 ESLint 以支持您项目的语言选项。
指定环境
环境提供预定义的全局变量。可用的环境有:
browser
- 浏览器全局变量。node
- Node.js 全局变量和 Node.js 范围。commonjs
- CommonJS 全局变量和 CommonJS 范围(将其用于使用 Browserify/WebPack 的仅浏览器代码)。shared-node-browser
- Node.js 和浏览器通用的全局变量。es6
- 启用除模块之外的所有 ECMAScript 6 功能(这会自动将ecmaVersion
解析器选项设置为 6)。es2016
- 添加所有 ECMAScript 2016 全局变量并自动将ecmaVersion
解析器选项设置为 7。es2017
- 添加所有 ECMAScript 2017 全局变量并自动将ecmaVersion
解析器选项设置为 8。es2018
- 添加所有 ECMAScript 2018 全局变量并自动将ecmaVersion
解析器选项设置为 9。es2019
- 添加所有 ECMAScript 2019 全局变量并自动将ecmaVersion
解析器选项设置为 10。es2020
- 添加所有 ECMAScript 2020 全局变量并自动将ecmaVersion
解析器选项设置为 11。es2021
- 添加所有 ECMAScript 2021 全局变量并自动将ecmaVersion
解析器选项设置为 12。es2022
- 添加所有 ECMAScript 2022 全局变量并自动将ecmaVersion
解析器选项设置为 13。worker
- 网络工作者全局变量。amd
- 根据 amd 规范将require()
和define()
定义为全局变量。mocha
- 添加所有 Mocha 测试全局变量。jasmine
- 为版本 1.3 和 2.0 添加所有 Jasmine 测试全局变量。jest
- Jest 全局变量。phantomjs
- PhantomJS 全局变量。protractor
- 量角器全局变量。qunit
- QUnit 全局变量。jquery
- jQuery 全局变量。prototypejs
- Prototype.js 全局变量。shelljs
- ShellJS 全局变量。meteor
- Meteor 全局变量。mongo
- MongoDB 全局变量。applescript
- AppleScript 全局变量。nashorn
- Java 8 Nashorn 全局变量。serviceworker
- Service Worker 全局变量。atomtest
- Atom 测试助手全局变量。embertest
- Ember 测试助手全局变量。webextensions
- WebExtensions 全局变量。greasemonkey
- GreaseMonkey 全局变量。
这些环境不是相互排斥的,因此您可以一次定义多个环境。
环境可以在文件内、配置文件中或使用 --env
命令行 标志指定。
使用配置注释
cdv4TTc4TbfW7zjgcN6W3rYlsEMPT24D31Cw7YZTyo8536aMFOGyjcBaK5BjKUsh/FiP55hhwr/Y5PTwp36p1lvx+hap+P6RTlkKBPKX7MZ9Qa77q7nHrC2WdxmojvC1
/* eslint-env node, mocha */
h5cL5pI5ZkP7VRr172mLGCgLj/anygFNvqpnABsZtnivzWJ12nDjsDuWaw5b9MDE
使用配置文件
VwWO+m8Vhm2DtLv/vSXcai9ZHr2b0G8+cx/vc1rDXCzlCqZsbN/m7eN/N/RvXcqMt+W+TIX09XNc+tu5KR/bovNFhTm0ZXQ8Jj7UP6I8ESBI/jKxFdEfpxwL7Ts2y18ShUDyLxt+BPQzdnofMnbWzGG2bb3uUZKnYxZ5u+2oBMD3sjIiFhUCdPz/I5B8k4e5KBRJufb/YEiknEnXjaZY5t0A5egzYrYkiZ76x6v+yhq/GGHlssTAskOHNyI7iG3pwxiYvyXii2D9H1YB1rnNVw==
{
"env": {
"browser": true,
"node": true
}
}
Cn1msdtCWnWU6JKfhrJ8cJw/SF4uG6klIk4DaQqzKus8/yp2C/S9axnHLMPoTzRq
{
"name": "mypackage",
"version": "0.0.1",
"eslintConfig": {
"env": {
"browser": true,
"node": true
}
}
}
tCRDsNy6aP6qBJ8u4t0FRA==
---
env:
browser: true
node: true
使用插件
/Ka77O5hk3Bj1PgDn3UIoyjNzat0B9CZ6qikiCRRDQIBT59H823h++iQJ4JSZLxMuHagIgZyyQj7A0iVHauIqWnwSUAe/X6IOhkqeIoBGuE3BJtfn/rHU9oVhtIaSXLDEut/u1FE0FhLpe7J20XXQLOngPMu/rJlH/KLpnqCZMGt4bOtocOyiCmiRFl/CbPX5Uqim8mD+a6gXlH7xNeaVOaw1hYiNF+H4PfMjDakKMft8+XkSGOsgHcU0yjc64BR
{
"plugins": ["example"],
"env": {
"example/custom": true
}
}
Cn1msdtCWnWU6JKfhrJ8cJw/SF4uG6klIk4DaQqzKus8/yp2C/S9axnHLMPoTzRq
{
"name": "mypackage",
"version": "0.0.1",
"eslintConfig": {
"plugins": ["example"],
"env": {
"example/custom": true
}
}
}
指定全局变量
GWjSDlReaNLQXWiWJV8yOgSh0OjqmPnrBghYxv4vVBQKT/bqC+DL6HloOPsFQMFa0O4rpmO0qoN+GDRwsJ+D+hLorC+4eoP7nJ3Eva3hLZD14c9f/LheQL0h0gTOlaMRLV7+F0nCFrxj2us5vkwz+yiKbXUCoJNkb5WcwjseENIsowYPmz0NJnz53xJ/HyKPgJJg6cXGoUg+rJu1zy95mv6ONGBaH39B0qawQDxPFmGSm8bKVmR86drChxpo36M2fPH4sirtYcnmIm9bu2ehxenLI9+sXxuEelg0a44X0TxZD+aC4ohZVNU8M4dlWEcOuqv5x3xzUWnwQdSmc4q/Jrh/HraRtoO5hM1E+FRs4XllAutXyeGj45w2OB9aWR2xUuprNW78W/RXLeZG7fXBhdEcSgU3LaEp57s7HtKuvlw7DS2MCOWXsE3UuvF2asFcPvFCRVPfhHqCUJACoVwMu1PD+rylpUZmFbs6vMrbjMmjRgKt9e5bI/5i6o2zcLfxsShTkP5fNimmXePLBRv6GQD4pisg+pJWH2RiMoR9wAz6DWGS+PwFJ6dBoEmk6NXW
使用配置注释
ZWuQUJXq/TdS1lgyQ6YT4C+djLPPe3aqAL/X/hDFONuqXVELlcTlgVspV8SjcY0PxmEDIZrX8chqrVhkRvgRzl+7vWLYI+gimz9A8x13ao6e++f2BAThc342pzyJ3Olc
/* global var1, var2 */
HvP8balfqPh6Pu2Yj3kgv+Dez9bpTddnO0fcb6K55rjn7EbthpmXR27OZB2B5mqfqgTSYGSXMm2wnDcP0YRY844qp9pO80s9oH/zGZdoIvgQ1ZAG2vnJFBre/777qP01Fob9B/S56KZPDb5BpVOFEK6b9hn2i8i9MkoQFFepc2o6E5teV1eStCKuxSLtkIU6ZPnJinjveiMDtcODnrtqHCJmdnM3/cdDB9Eo31qe2T4vzYv/BZLVAt0ytA13Gm0XsNUCNo+ubVuYfjEEpGMG9KQNC4qs3ZfA3TwhWAAkRge/SZQbIzV9EgVA5aXjvXV+4omJykfBBHjol5eS/PTmhQ==
/* global var1:writable, var2:writable */
使用配置文件
VwWO+m8Vhm2DtLv/vSXcan6n+o4Sxq+G40dOcyCuDycn5gg3mdwjzKcFFCNcQTyPeyGLKVRcO42zAIqdsqOZVr8nFU1StQXSJKSa14rfBgGe4abbigGXFRKN+F38++ok40I61CqNagKCnCZwdI3eWkwbRTScZWvR27f8OSio2t9WyzfynwJguYeze0V/MW5xjNc6t39aaev2DJZJ6Xsv3oXWTRmIjXaMMXQQYul0pS31F4Ox1j0vD4eXEviF6sGebR+2h92l4nMPNYXMVC0wYAAOU+owbA9JWbh8iyP4+VbI2EjU7Wgq2mZd/+iDIsbdcal6kIjBnU02xjopnxr3duOSxmS6f7+HRM8CIGhRyjdSu//lTUfxuxVnfec2dT2WpkKBmE3TIH5s3/dFLE1NmFbL19G4rpCxsqiL924/QOI=
{
"globals": {
"var1": "writable",
"var2": "readonly"
}
}
tCRDsNy6aP6qBJ8u4t0FRA==
---
globals:
var1: writable
var2: readonly
TtnNSGWZwf0iaT8RULHPFeGj2h52xiIrerEUW0k66sp78ix6yr1u+oz8NAsJ+Y+ptlboBXlehdNx+9OZP/c4dMBzc/zEj/LG/tvPssgc76auB4L5zCyZNjWWreHerdJBM+71UfFz93ZyrkOG0LjzCD0EzCVweSOKIVf8itKmqM8=
e8yTS9B2ZTlbeEp+lKFldtAhwVyCmncP/1MmTG0lTwJxNK3nHF/WE7ySS4gIqy/XGgey9Wv3idDDrvk7ZNYRTry77nPTl43H1jYY9Gd2+ox4Rh0bvN/dT7p+JtTYbiOk41uRdRAXi0e+Oj31cZOzjptgI/+iIjRHXUNIYg4QAk5zbPoFL3EMWVQMYh8hSPnvHrl1pmUhEqGOQeHceWqZ6ZCs+tLkd19DUlH6CU8R4X3d8FKRFgqn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