|
7 | 7 |
|
8 | 8 | --- |
9 | 9 |
|
10 | | -An opinionated ESLint ruleset targeting TypeScript + React web apps |
| 10 | +An opinionated ESLint ruleset targeting TypeScript + React web apps. |
11 | 11 |
|
12 | 12 | ## Requirements |
13 | 13 |
|
14 | | -- ESLint `^8.48.0` |
| 14 | +- ESLint `^9.0.0` |
| 15 | +- Node `>=18.18` |
15 | 16 |
|
16 | 17 | ## Installation |
17 | 18 |
|
18 | | -1. Install `eslint` and `@getresponse/eslint-config`: |
| 19 | +```bash |
| 20 | +npm i -D eslint @getresponse/eslint-config |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +Create `eslint.config.js` in your project root: |
| 26 | + |
| 27 | +```js |
| 28 | +import config from '@getresponse/eslint-config'; |
| 29 | + |
| 30 | +export default config; |
| 31 | +``` |
19 | 32 |
|
20 | | - ```bash |
21 | | - npm i -D eslint @getresponse/eslint-config |
22 | | - ``` |
| 33 | +With local overrides: |
23 | 34 |
|
24 | | -2. Add `"extends": "@getresponse/eslint-config"` to your ESLint [configuration file](https://eslint.org/docs/latest/user-guide/configuring/configuration-files) |
| 35 | +```js |
| 36 | +import { defineConfig } from 'eslint/config'; |
| 37 | +import config from '@getresponse/eslint-config'; |
| 38 | + |
| 39 | +export default defineConfig( |
| 40 | + config, |
| 41 | + { |
| 42 | + files: ['src/legacy/**/*.ts'], |
| 43 | + rules: { |
| 44 | + '@typescript-eslint/no-explicit-any': 'off', |
| 45 | + }, |
| 46 | + }, |
| 47 | +); |
| 48 | +``` |
25 | 49 |
|
26 | 50 | ## TypeScript project files |
27 | 51 |
|
28 | | -Since `@typescript-eslint` v8, all linted `.ts`/`.tsx` files must be included in your `tsconfig.json`. Files outside the project will cause an error when type-aware rules are active. Make sure your `tsconfig.json` (or a dedicated `tsconfig.eslint.json`) covers all files you want to lint: |
| 52 | +Rules requiring type information use `projectService` (auto-discovery). The package automatically: |
| 53 | + |
| 54 | +- finds the nearest `tsconfig.json` for each linted file, |
| 55 | +- uses `tsconfig.eslint.json` (if present in the project root) as fallback for files outside any project — typical for config files, scripts, and tests. |
| 56 | + |
| 57 | +If you have files outside `src/` you want linted, point them at a dedicated `tsconfig.eslint.json`: |
29 | 58 |
|
30 | 59 | ```json |
31 | 60 | { |
32 | | - "include": ["src/**/*", "tests/**/*"] |
| 61 | + "extends": "./tsconfig.json", |
| 62 | + "include": ["src/**/*", "tests/**/*", "scripts/**/*"] |
33 | 63 | } |
34 | 64 | ``` |
35 | 65 |
|
36 | 66 | ## Dynamic rules |
37 | 67 |
|
38 | | -Rules for the following tools are enabled automatically when the corresponding package is detected in your `package.json`: |
| 68 | +Plugin rulesets are enabled automatically when the corresponding package is detected in your `package.json`: |
39 | 69 |
|
40 | 70 | - `typescript` |
41 | | -- `react` |
| 71 | +- `react` (+ `react-hooks`) |
42 | 72 | - `jest` |
43 | 73 | - `@playwright/test` / `playwright` |
44 | 74 |
|
45 | 75 | ## Mixins |
46 | 76 |
|
47 | | -Additional opt-in rulesets are available: |
| 77 | +Additional opt-in rulesets: |
48 | 78 |
|
49 | 79 | ```js |
50 | | -// .eslintrc.js |
51 | | -module.exports = { |
52 | | - extends: [ |
53 | | - '@getresponse/eslint-config', |
54 | | - '@getresponse/eslint-config/mixins/a11y', |
55 | | - ], |
56 | | -}; |
| 80 | +import { defineConfig } from 'eslint/config'; |
| 81 | +import config from '@getresponse/eslint-config'; |
| 82 | +import a11y from '@getresponse/eslint-config/mixins/a11y'; |
| 83 | + |
| 84 | +export default defineConfig(config, a11y); |
57 | 85 | ``` |
58 | 86 |
|
59 | | -| Mixin | Description | |
60 | | -|---|---| |
| 87 | +| Mixin | Description | |
| 88 | +|------------------------------------------|---| |
61 | 89 | | `@getresponse/eslint-config/mixins/a11y` | Accessibility rules via `eslint-plugin-jsx-a11y` | |
62 | 90 |
|
63 | 91 | ## Rules list |
|
0 commit comments