|
| 1 | +--- |
| 2 | +title: eslint-plugin-turbo |
| 3 | +description: Learn more about eslint-plugin-turbo. |
| 4 | +--- |
| 5 | + |
| 6 | +import { PackageManagerTabs, Tab } from '#/components/tabs'; |
| 7 | + |
| 8 | +[The `eslint-plugin-turbo` package](https://www.npmjs.com/package/eslint-plugin-turbo) 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. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +Install `eslint-config-turbo` into the location where your ESLint configuration is held: |
| 13 | + |
| 14 | +<PackageManagerTabs> |
| 15 | + <Tab> |
| 16 | + |
| 17 | + ```bash title="Terminal" |
| 18 | + npm i --save-dev eslint-config-turbo -w @acme/eslint-config |
| 19 | + ``` |
| 20 | + |
| 21 | + </Tab> |
| 22 | + <Tab> |
| 23 | + |
| 24 | + ```bash title="Terminal" |
| 25 | + yarn workspace @acme/eslint-config add eslint-config-turbo --dev |
| 26 | + ``` |
| 27 | + |
| 28 | + </Tab> |
| 29 | + <Tab> |
| 30 | + |
| 31 | + ```bash title="Terminal" |
| 32 | + pnpm add eslint-config-turbo --filter=@repo/eslint-config |
| 33 | + ``` |
| 34 | + |
| 35 | + </Tab> |
| 36 | +</PackageManagerTabs> |
| 37 | + |
| 38 | +## Usage (Flat Config `eslint.config.js`) |
| 39 | + |
| 40 | +ESLint v9 uses the Flat Config format seen below: |
| 41 | + |
| 42 | +```js title="./packages/eslint-config/base.js" |
| 43 | +import turbo from 'eslint-plugin-turbo'; |
| 44 | + |
| 45 | +export default [turbo.configs['flat/recommended']]; |
| 46 | +``` |
| 47 | + |
| 48 | +Otherwise, you may configure the rules you want to use under the rules section. |
| 49 | + |
| 50 | +```js title="./packages/eslint-config/base.js" |
| 51 | +import turbo from 'eslint-plugin-turbo'; |
| 52 | + |
| 53 | +export default [ |
| 54 | + { |
| 55 | + plugins: { |
| 56 | + turbo, |
| 57 | + }, |
| 58 | + rules: { |
| 59 | + 'turbo/no-undeclared-env-vars': 'error', |
| 60 | + }, |
| 61 | + }, |
| 62 | +]; |
| 63 | +``` |
| 64 | + |
| 65 | +## Example (Flat Config `eslint.config.js`) |
| 66 | + |
| 67 | +```js title="./packages/eslint-config/base.js" |
| 68 | +import turbo from 'eslint-plugin-turbo'; |
| 69 | + |
| 70 | +export default [ |
| 71 | + { |
| 72 | + plugins: { |
| 73 | + turbo, |
| 74 | + }, |
| 75 | + rules: { |
| 76 | + 'turbo/no-undeclared-env-vars': [ |
| 77 | + 'error', |
| 78 | + { |
| 79 | + allowList: ['^ENV_[A-Z]+$'], |
| 80 | + }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + }, |
| 84 | +]; |
| 85 | +``` |
| 86 | + |
| 87 | +## Usage (Legacy `eslintrc*`) |
| 88 | + |
| 89 | +Add `turbo` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix: |
| 90 | + |
| 91 | +```json title="./packages/eslint-config/base.json" |
| 92 | +{ |
| 93 | + "plugins": ["turbo"] |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +Then configure the rules you want to use under the rules section. |
| 98 | + |
| 99 | +```json title="./packages/eslint-config/base.json" |
| 100 | +{ |
| 101 | + "rules": { |
| 102 | + "turbo/no-undeclared-env-vars": "error" |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +## Example (Legacy `eslintrc*`) |
| 108 | + |
| 109 | +```json title="./packages/eslint-config/base.json" |
| 110 | +{ |
| 111 | + "plugins": ["turbo"], |
| 112 | + "rules": { |
| 113 | + "turbo/no-undeclared-env-vars": [ |
| 114 | + "error", |
| 115 | + { |
| 116 | + "allowList": ["^ENV_[A-Z]+$"] |
| 117 | + } |
| 118 | + ] |
| 119 | + } |
| 120 | +} |
| 121 | +``` |
0 commit comments