配置 JavaScript 版本
要配置 ESLint 用于评估 JavaScript 的 JavaScript (ECMAScript) 版本,请使用 ecmaVersion 属性。该属性确定哪些全局变量和语法在您的代码中有效,可以设置为版本号(例如 6)、年份号(例如 2022)或 "latest"(对于 ESLint 支持的最新版本)。默认情况下,ecmaVersion 设置为 "latest",建议保留此默认值,除非您需要确保将 JavaScript 代码评估为旧版本。例如,一些较旧的运行时可能只允许 ECMAScript 5,在这种情况下,您可以像这样配置 ESLint:
To configure the version of JavaScript (ECMAScript) that ESLint uses to evaluate your JavaScript, use the ecmaVersion property. This property determines which global variables and syntax are valid in your code and can be set to the version number (such as 6), the year number (such as 2022), or "latest" (for the most recent version that ESLint supports). By default, ecmaVersion is set to "latest" and it's recommended to keep this default unless you need to ensure that your JavaScript code is evaluated as an older version. For example, some older runtimes might only allow ECMAScript 5, in which case you can configure ESLint like this:
export default [
{
files: ["**/*.js"],
languageOptions: {
ecmaVersion: 5
}
}
];