|
1 | | -## @dagster-io/eslint-config |
| 1 | +# @dagster-io/eslint-config |
2 | 2 |
|
3 | | -Shared eslint configuration to be used in Dagster apps. |
| 3 | +Shared ESLint configuration for Dagster applications. |
| 4 | + |
| 5 | +**Version 2.x+** requires **ESLint 9** and uses the flat config format. |
| 6 | + |
| 7 | +For ESLint 8 support, use version 1.x. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +yarn add -D @dagster-io/eslint-config eslint@^9.0.0 prettier@^3.3.3 |
| 13 | +``` |
4 | 14 |
|
5 | 15 | ## Usage |
6 | 16 |
|
7 | | -### 1. Install |
| 17 | +### ESLint 9 Flat Config (eslint.config.js) |
| 18 | + |
| 19 | +Create an `eslint.config.js` file in your project root: |
| 20 | + |
| 21 | +```javascript |
| 22 | +const dagsterConfig = require('@dagster-io/eslint-config'); |
| 23 | + |
| 24 | +module.exports = [ |
| 25 | + ...dagsterConfig, |
| 26 | + // Your custom overrides here |
| 27 | + { |
| 28 | + rules: { |
| 29 | + // Override specific rules |
| 30 | + }, |
| 31 | + }, |
| 32 | +]; |
| 33 | +``` |
| 34 | + |
| 35 | +### With Ignores |
| 36 | + |
| 37 | +```javascript |
| 38 | +const dagsterConfig = require('@dagster-io/eslint-config'); |
| 39 | + |
| 40 | +module.exports = [ |
| 41 | + ...dagsterConfig, |
| 42 | + { |
| 43 | + ignores: ['dist/**', 'build/**', '*.config.js'], |
| 44 | + }, |
| 45 | +]; |
| 46 | +``` |
| 47 | + |
| 48 | +### With Additional Plugins |
| 49 | + |
| 50 | +```javascript |
| 51 | +const dagsterConfig = require('@dagster-io/eslint-config'); |
| 52 | +const storybookPlugin = require('eslint-plugin-storybook'); |
| 53 | + |
| 54 | +module.exports = [ |
| 55 | + ...dagsterConfig, |
| 56 | + ...storybookPlugin.configs['flat/recommended'], |
| 57 | + { |
| 58 | + // Additional configuration |
| 59 | + }, |
| 60 | +]; |
| 61 | +``` |
| 62 | + |
| 63 | +## Migration from v1 to v2 |
| 64 | + |
| 65 | +### Step 1: Upgrade Dependencies |
8 | 66 |
|
9 | 67 | ```bash |
10 | | -yarn -D add @dagster-io/eslint-config |
| 68 | +yarn add -D eslint@^9.0.0 @dagster-io/eslint-config@^2.0.0 |
11 | 69 | ``` |
12 | 70 |
|
13 | | -### 2. Add to your project's eslint configuration |
| 71 | +### Step 2: Rename Config File |
14 | 72 |
|
15 | | -```js |
16 | | -// .eslintrc.js |
| 73 | +Rename `.eslintrc.js` → `eslint.config.js` |
| 74 | + |
| 75 | +### Step 3: Update Config Format |
| 76 | + |
| 77 | +**Before (.eslintrc.js):** |
| 78 | + |
| 79 | +```javascript |
17 | 80 | module.exports = { |
18 | 81 | extends: ['@dagster-io/eslint-config'], |
| 82 | + ignorePatterns: ['dist/**'], |
| 83 | + overrides: [ |
| 84 | + { |
| 85 | + files: ['*.test.ts'], |
| 86 | + rules: { |
| 87 | + '@typescript-eslint/no-explicit-any': 'off', |
| 88 | + }, |
| 89 | + }, |
| 90 | + ], |
19 | 91 | }; |
20 | 92 | ``` |
21 | 93 |
|
22 | | -If you are extending other configurations, put those first. |
| 94 | +**After (eslint.config.js):** |
| 95 | + |
| 96 | +```javascript |
| 97 | +const dagsterConfig = require('@dagster-io/eslint-config'); |
| 98 | + |
| 99 | +module.exports = [ |
| 100 | + ...dagsterConfig, |
| 101 | + { |
| 102 | + ignores: ['dist/**'], |
| 103 | + }, |
| 104 | + { |
| 105 | + files: ['*.test.ts'], |
| 106 | + rules: { |
| 107 | + '@typescript-eslint/no-explicit-any': 'off', |
| 108 | + }, |
| 109 | + }, |
| 110 | +]; |
| 111 | +``` |
| 112 | + |
| 113 | +### Step 4: Update Scripts (if needed) |
| 114 | + |
| 115 | +ESLint 9 with flat config auto-detects files and config location. |
| 116 | + |
| 117 | +**Before:** |
| 118 | + |
| 119 | +```json |
| 120 | +{ |
| 121 | + "scripts": { |
| 122 | + "lint": "eslint . --ext .ts,.tsx -c .eslintrc.js" |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +**After:** |
| 128 | + |
| 129 | +```json |
| 130 | +{ |
| 131 | + "scripts": { |
| 132 | + "lint": "eslint ." |
| 133 | + } |
| 134 | +} |
| 135 | +``` |
23 | 136 |
|
24 | | -```js |
| 137 | +### Key Differences in Flat Config |
| 138 | + |
| 139 | +1. **Config is an array** - Multiple config objects can be specified |
| 140 | +2. **No `extends`** - Configs are imported and spread: `...dagsterConfig` |
| 141 | +3. **Ignores replace ignorePatterns** - Use `ignores: ['pattern']` in config objects |
| 142 | +4. **Overrides are separate objects** - Each override is its own config object in the array |
| 143 | +5. **File patterns in `files` key** - Override specific files with `files: ['*.test.ts']` |
| 144 | + |
| 145 | +## Custom Rules |
| 146 | + |
| 147 | +This config includes custom Dagster-specific ESLint rules: |
| 148 | + |
| 149 | +### `dagster-rules/missing-graphql-variables-type` |
| 150 | + |
| 151 | +Ensures GraphQL queries and mutations specify the Variables type parameter. |
| 152 | + |
| 153 | +**❌ Incorrect:** |
| 154 | + |
| 155 | +```typescript |
| 156 | +const {data} = useQuery<SomeQuery>(SOME_QUERY); |
| 157 | +``` |
| 158 | + |
| 159 | +**✅ Correct:** |
| 160 | + |
| 161 | +```typescript |
| 162 | +const {data} = useQuery<SomeQuery, SomeQueryVariables>(SOME_QUERY); |
| 163 | +``` |
| 164 | + |
| 165 | +### `dagster-rules/no-oss-imports` |
| 166 | + |
| 167 | +Prevents relative imports of `.oss` files and enforces absolute path imports. |
| 168 | + |
| 169 | +**❌ Incorrect:** |
| 170 | + |
| 171 | +```typescript |
| 172 | +import {Component} from './Component.oss'; |
| 173 | +``` |
| 174 | + |
| 175 | +**✅ Correct:** |
| 176 | + |
| 177 | +```typescript |
| 178 | +import {Component} from 'shared/components/Component.oss'; |
| 179 | +``` |
| 180 | + |
| 181 | +### `dagster-rules/no-apollo-client` |
| 182 | + |
| 183 | +Enforces using Dagster's wrapped Apollo client with performance instrumentation. |
| 184 | + |
| 185 | +**❌ Incorrect:** |
| 186 | + |
| 187 | +```typescript |
| 188 | +import {useQuery} from '@apollo/client'; |
| 189 | +``` |
| 190 | + |
| 191 | +**✅ Correct:** |
| 192 | + |
| 193 | +```typescript |
| 194 | +import {useQuery} from '../apollo-client'; |
| 195 | +// or |
| 196 | +import {useQuery} from '@dagster-io/ui-core/apollo-client'; |
| 197 | +``` |
| 198 | + |
| 199 | +### `dagster-rules/no-react-router-route` |
| 200 | + |
| 201 | +Enforces using Dagster's custom `Route` component instead of react-router-dom's. |
| 202 | + |
| 203 | +**❌ Incorrect:** |
| 204 | + |
| 205 | +```typescript |
| 206 | +import {Route} from 'react-router-dom'; |
| 207 | +``` |
| 208 | + |
| 209 | +**✅ Correct:** |
| 210 | + |
| 211 | +```typescript |
| 212 | +import {Route} from '../app/Route'; |
| 213 | +// or |
| 214 | +import {Route} from '@dagster-io/ui-core/app/Route'; |
| 215 | +``` |
| 216 | + |
| 217 | +### `dagster-rules/missing-shared-import` |
| 218 | + |
| 219 | +Validates that imports using the `shared/` path reference files ending with `.oss`. |
| 220 | + |
| 221 | +## Included Rules and Plugins |
| 222 | + |
| 223 | +This config includes: |
| 224 | + |
| 225 | +- **TypeScript** - `@typescript-eslint` recommended rules |
| 226 | +- **React** - React recommended rules + JSX runtime |
| 227 | +- **Jest** - Jest recommended rules |
| 228 | +- **Prettier** - Prettier integration with auto-formatting |
| 229 | +- **Import** - Import ordering and cycle detection |
| 230 | +- **React Hooks** - Rules of Hooks and exhaustive deps |
| 231 | +- **Unused Imports** - Auto-removal of unused imports |
| 232 | +- **Custom Dagster Rules** - Dagster-specific linting rules |
| 233 | + |
| 234 | +## Rule Highlights |
| 235 | + |
| 236 | +- **Import Ordering** - Automatically sorts imports by type and alphabetically |
| 237 | +- **No Default Exports** - Enforces named exports for better refactoring |
| 238 | +- **No Unused Imports** - Automatically removes unused imports |
| 239 | +- **Restricted Imports** - Prevents use of deprecated libraries (moment, lodash, etc.) |
| 240 | +- **React Best Practices** - Enforces modern React patterns |
| 241 | +- **TypeScript Strictness** - Disallows non-null assertions and other unsafe patterns |
| 242 | + |
| 243 | +## Compatibility |
| 244 | + |
| 245 | +- **ESLint**: ^9.0.0 |
| 246 | +- **Node.js**: 18.18+, 20.9+, 21+ |
| 247 | +- **TypeScript**: Any version (via typescript-eslint v8) |
| 248 | + |
| 249 | +## Legacy Version (ESLint 8) |
| 250 | + |
| 251 | +If you need ESLint 8 support, install version 1.x: |
| 252 | + |
| 253 | +```bash |
| 254 | +yarn add -D @dagster-io/eslint-config@^1.0.0 eslint@^8.57.1 |
| 255 | +``` |
| 256 | + |
| 257 | +Then use the legacy `.eslintrc.js` format: |
| 258 | + |
| 259 | +```javascript |
25 | 260 | // .eslintrc.js |
26 | 261 | module.exports = { |
27 | | - extends: ['some-other-config', '@dagster-io/eslint-config'], |
| 262 | + extends: ['@dagster-io/eslint-config'], |
28 | 263 | }; |
29 | 264 | ``` |
30 | 265 |
|
31 | | -You can add other rules and settings to your `.eslintrc` as needed. |
| 266 | +## Contributing |
| 267 | + |
| 268 | +This package is part of the Dagster monorepo. To make changes: |
| 269 | + |
| 270 | +1. Update the config in `/js_modules/dagster-ui/packages/eslint-config` |
| 271 | +2. Test locally with `yarn lint` and `yarn test` |
| 272 | +3. Update version in `package.json` |
| 273 | +4. Update `CHANGELOG.md` with changes |
| 274 | +5. Submit a PR |
| 275 | + |
| 276 | +## License |
| 277 | + |
| 278 | +Apache-2.0 |
0 commit comments