@panates/eslint-config-react 2.3.3 → 2.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,11 +4,11 @@ React rules for Panates' ESLint config, on top of
4
4
  [`@panates/eslint-config-ts`](https://github.com/panates/javascript/tree/main/packages/eslint-config-ts).
5
5
  For TypeScript React projects, ESLint 10 and flat config.
6
6
 
7
- | Config | For | Brings |
8
- | --- | --- | --- |
9
- | `configs.react` | any React project in a browser | [`@eslint-react`](https://eslint-react.xyz) for components and JSX, React's own [`react-hooks`](https://react.dev/reference/eslint-plugin-react-hooks) for hooks and the React Compiler |
10
- | `@panates/eslint-config-react/next` | Next.js | the above, plus [`@next/eslint-plugin-next`](https://nextjs.org/docs/app/api-reference/config/eslint) at `core-web-vitals` |
11
- | `@panates/eslint-config-react/vite` | Vite | the above, plus [`react-refresh`](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) for hot reload |
7
+ | Config | For | Brings |
8
+ | ----------------------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
+ | `configs.react` | any React project in a browser | [`@eslint-react`](https://eslint-react.xyz) for components and JSX, React's own [`react-hooks`](https://react.dev/reference/eslint-plugin-react-hooks) for hooks and the React Compiler |
10
+ | `@panates/eslint-config-react/next` | Next.js | the above, plus [`@next/eslint-plugin-next`](https://nextjs.org/docs/app/api-reference/config/eslint) at `core-web-vitals` |
11
+ | `@panates/eslint-config-react/vite` | Vite | the above, plus [`react-refresh`](https://github.com/ArnaudBarre/eslint-plugin-react-refresh) for hot reload |
12
12
 
13
13
  ## Install
14
14
 
@@ -48,6 +48,18 @@ your own goes in an `ignores` block of your own.
48
48
 
49
49
  `configPatches.react` is the React layer alone, to add on top of a config of your own.
50
50
 
51
+ **A library** - a package other projects install, with `react` as a peer - names the oldest React it
52
+ supports, so rules for an idiom newer than that stay quiet:
53
+
54
+ ```js
55
+ // eslint.config.mjs - a library whose peer range is react >=18
56
+ export default [...panatesReact.configs.react, { settings: { 'react-x': { version: '18.0.0' } } }];
57
+ ```
58
+
59
+ `@eslint-react` reads its React version from there; left out, it detects the React installed - a
60
+ library's own dev copy, usually the newest - and asks for React 19's `ref` prop in place of
61
+ `forwardRef`, or `use()` in place of `useContext`, which its React 18 consumers do not have.
62
+
51
63
  ## Notes
52
64
 
53
65
  - **`@eslint-react`, not `eslint-plugin-react`**: the latter, and `eslint-plugin-jsx-a11y`, support
@@ -55,6 +67,11 @@ your own goes in an `ignores` block of your own.
55
67
  - **Hooks are checked once.** Rules both plugins have (`rules-of-hooks`, `exhaustive-deps`, the
56
68
  React Compiler ones) are left to `react-hooks`.
57
69
  - **Relative imports need no extension** (`import-x/extensions` is off) - a bundler resolves them.
70
+ - **An index is a valid key** (`@eslint-react/no-array-index-key` is off): it is the right one for a
71
+ list of positions - one box per OTP digit, the parts of a formatted date - and the rule cannot
72
+ tell such a list from one that reorders. Key a list that reorders by something stable.
73
+ - **The Next entry takes `@next/eslint-plugin-next` 15 or 16.** 15 ships its configs in the
74
+ eslintrc shape and the flat ones under `flatConfig`; the entry reads whichever is there.
58
75
  - **A prettier plugin named in a package's prettier config is resolved from where ESLint runs.**
59
76
  Formatting is checked through `eslint-plugin-prettier`, and prettier looks a plugin name such as
60
77
  `'prettier-plugin-tailwindcss'` up from the working directory - so `eslint` run at a monorepo's
package/configs/next.d.ts CHANGED
@@ -2,4 +2,10 @@ import { Linter } from 'eslint';
2
2
 
3
3
  declare const config: Linter.Config[];
4
4
 
5
+ /** Next's `core-web-vitals` config in flat form, from a 15.x or a 16.x `@next/eslint-plugin-next`. */
6
+ export declare function coreWebVitals(plugin: {
7
+ configs: Record<string, unknown>;
8
+ flatConfig?: Record<string, unknown>;
9
+ }): Linter.Config;
10
+
5
11
  export default config;
package/configs/next.js CHANGED
@@ -1,6 +1,20 @@
1
1
  import nextPlugin from '@next/eslint-plugin-next';
2
2
  import reactConfig from './react.js';
3
3
 
4
+ /**
5
+ * Next's `core-web-vitals` config in flat form, from either plugin line the peer range takes in.
6
+ *
7
+ * 16 ships `configs` flat and has no `flatConfig`; 15 ships `configs` in the eslintrc shape -
8
+ * `plugins` an array of names, which flat config rejects outright - and the flat ones under
9
+ * `flatConfig`. Measured on 16.4.2 and 15.5.28. Reading `configs` alone made this entry work on 16
10
+ * only, while its peer range said `>=15`.
11
+ *
12
+ * @param {typeof nextPlugin} plugin
13
+ */
14
+ export function coreWebVitals(plugin) {
15
+ return plugin.flatConfig?.coreWebVitals ?? plugin.configs['core-web-vitals'];
16
+ }
17
+
4
18
  /**
5
19
  * A Next.js application: the React config plus Next's own rules, at the stricter
6
20
  * `core-web-vitals` level `create-next-app` sets up (it includes `recommended`).
@@ -17,7 +31,7 @@ export default [
17
31
  },
18
32
  ...reactConfig,
19
33
  {
20
- ...nextPlugin.configs['core-web-vitals'],
34
+ ...coreWebVitals(nextPlugin),
21
35
  name: 'panates/next',
22
36
  },
23
37
  ];
@@ -34,6 +34,12 @@ const duplicatesOff = Object.fromEntries(
34
34
  * `import-x/extensions` is off: the base config asks for `.js` on a relative import, which is Node's
35
35
  * ESM rule, while a React project is built by a bundler (Next, Vite) and imports without one.
36
36
  * Measured on `abisena-tr`: 272 reports, every one an ordinary `./component` import.
37
+ *
38
+ * `@eslint-react/no-array-index-key` is off: an index is the right key for a list whose items are
39
+ * their position - one input box per OTP digit, the parts of a formatted date, a consumer's array of
40
+ * actions with no identity of its own - and the rule cannot tell such a list from one that reorders.
41
+ * Measured on `panates/peacox-ui`: 12 reports, each a positional list or a list with no other key.
42
+ * Keying a list that does reorder by something stable stays the author's call.
37
43
  */
38
44
  export default [
39
45
  {
@@ -52,6 +58,7 @@ export default [
52
58
  rules: {
53
59
  ...duplicatesOff,
54
60
  'import-x/extensions': 'off',
61
+ '@eslint-react/no-array-index-key': 'off',
55
62
  },
56
63
  },
57
64
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panates/eslint-config-react",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "React rules for Panates ESLint config, following our styleguide",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -11,13 +11,14 @@
11
11
  "./package.json": "./package.json"
12
12
  },
13
13
  "dependencies": {
14
- "@panates/eslint-config-ts": "^2.3.3"
14
+ "@panates/eslint-config-ts": "^2.3.5"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@eslint-react/eslint-plugin": ">=5",
18
18
  "@next/eslint-plugin-next": ">=15",
19
19
  "eslint-plugin-react-hooks": ">=7",
20
- "eslint-plugin-react-refresh": ">=0.5"
20
+ "eslint-plugin-react-refresh": ">=0.5",
21
+ "typescript": ">=6 <7"
21
22
  },
22
23
  "peerDependenciesMeta": {
23
24
  "@next/eslint-plugin-next": {
@@ -64,8 +65,9 @@
64
65
  "Bircan Yuruk <b.yuruk@panates.com>"
65
66
  ],
66
67
  "devDependencies": {
67
- "@eslint-react/eslint-plugin": "^5.28.2",
68
- "@next/eslint-plugin-next": "^16.4.2",
68
+ "@eslint-react/eslint-plugin": "^5.28.8",
69
+ "@next/eslint-plugin-next": "^16.4.5",
70
+ "@next/eslint-plugin-next-15": "npm:@next/eslint-plugin-next@15.5.28",
69
71
  "eslint-plugin-react-hooks": "^7.1.1",
70
72
  "eslint-plugin-react-refresh": "^0.5.7"
71
73
  },