eslint-config-turbo

eslint-config-turbo 软件包 帮助你查找代码中使用的、不属于 Turborepo 哈希计算的环境变量。源代码中使用的、在 turbo.json 中未考虑的环境变量将在编辑器中高亮显示,错误将显示为 ESLint 输出。

¥The eslint-config-turbo package helps you find environment variables that are used in your code that are not a part of Turborepo's hashing. Environment variables used in your source code that are not accounted for in turbo.json will be highlighted in your editor and errors will show as ESLint output.

安装

¥Installation

eslint-config-turbo 安装到保存 ESLint 配置的位置:

¥Install eslint-config-turbo into the location where your ESLint configuration is held:

Terminal
pnpm add eslint-config-turbo --filter=@repo/eslint-config

用法(扁平配置 eslint.config.js

¥Usage (Flat Config eslint.config.js)

./packages/eslint-config/base.js
import turboConfig from 'eslint-config-turbo/flat';
 
export default [
  ...turboConfig,
  // Other configuration
];

你还可以配置配置中可用的规则:

¥You can also configure rules available in the configuration:

./packages/eslint-config/base.js
import turboConfig from 'eslint-config-turbo/flat';
 
export default [
  ...turboConfig,
  // Other configuration
  {
    rules: {
      'turbo/no-undeclared-env-vars': [
        'error',
        {
          allowList: ['^ENV_[A-Z]+$'],
        },
      ],
    },
  },
];

用法(旧版 eslintrc*

¥Usage (Legacy eslintrc*)

turbo 添加到 eslint 配置文件的 extends 部分。你可以省略 eslint-config- 前缀:

¥Add turbo to the extends section of your eslint configuration file. You can omit the eslint-config- prefix:

./packages/eslint-config/base.json
{
  "extends": ["turbo"]
}

你还可以配置配置中可用的规则:

¥You can also configure rules available in the configuration:

./packages/eslint-config/base.json
{
  "plugins": ["turbo"],
  "rules": {
    "turbo/no-undeclared-env-vars": [
      "error",
      {
        "allowList": ["^ENV_[A-Z]+$"]
      }
    ]
  }
}