eslint-plugin-primer-react 8.4.0 → 8.5.0-rc.1eb9de5
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/.github/workflows/release_tracking.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/docs/rules/no-use-responsive-value.md +102 -0
- package/package-lock.json +9904 -0
- package/package.json +2 -2
- package/src/configs/recommended.js +1 -0
- package/src/index.js +1 -0
- package/src/rules/__tests__/no-use-responsive-value.test.js +133 -0
- package/src/rules/no-use-responsive-value.js +53 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# eslint-plugin-primer-react
|
|
2
2
|
|
|
3
|
+
## 8.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#443](https://github.com/primer/eslint-plugin-primer-react/pull/443) [`8865e3a`](https://github.com/primer/eslint-plugin-primer-react/commit/8865e3af43dfd302ed345c5b9243c32abe7cebad) Thanks [@hectahertz](https://github.com/hectahertz)! - Add no-use-responsive-value
|
|
8
|
+
|
|
3
9
|
## 8.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# no-use-responsive-value
|
|
2
|
+
|
|
3
|
+
Disallow using `useResponsiveValue` hook from `@primer/react` or local imports.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule prevents the use of the `useResponsiveValue` hook from:
|
|
8
|
+
|
|
9
|
+
- `@primer/react` package imports (including `/experimental` and `/deprecated` entrypoints)
|
|
10
|
+
- Local file imports (relative paths containing `useResponsiveValue`)
|
|
11
|
+
|
|
12
|
+
### Why?
|
|
13
|
+
|
|
14
|
+
This hook is not fully SSR compatible as it relies on `useMediaUnsafeSSR` without a `defaultState`. Using `getResponsiveAttributes` is preferred to avoid hydration mismatches. This rule helps enforce consistent usage of SSR-safe responsive patterns across the codebase.
|
|
15
|
+
|
|
16
|
+
## Examples
|
|
17
|
+
|
|
18
|
+
### ❌ Incorrect
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import {useResponsiveValue} from '@primer/react'
|
|
22
|
+
|
|
23
|
+
function Component() {
|
|
24
|
+
const value = useResponsiveValue(['sm', 'md', 'lg'])
|
|
25
|
+
return <div>{value}</div>
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import {Button, useResponsiveValue} from '@primer/react'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import {useResponsiveValue} from '@primer/react/experimental'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import {useResponsiveValue} from '../hooks/useResponsiveValue'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import useResponsiveValue from '../hooks/useResponsiveValue'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import {useResponsiveValue} from './useResponsiveValue'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### ✅ Correct
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import {Button} from '@primer/react'
|
|
53
|
+
|
|
54
|
+
function Component() {
|
|
55
|
+
// Use alternative responsive patterns
|
|
56
|
+
return <Button>Click me</Button>
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import {useResponsiveValue} from 'other-library'
|
|
62
|
+
|
|
63
|
+
function Component() {
|
|
64
|
+
// Using useResponsiveValue from a different library is allowed
|
|
65
|
+
const value = useResponsiveValue(['sm', 'md', 'lg'])
|
|
66
|
+
return <div>{value}</div>
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import {useCustomHook} from '../hooks/useCustomHook'
|
|
72
|
+
|
|
73
|
+
function Component() {
|
|
74
|
+
// Importing other hooks from local paths is allowed
|
|
75
|
+
const value = useCustomHook(['sm', 'md', 'lg'])
|
|
76
|
+
return <div>{value}</div>
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
function useResponsiveValue() {
|
|
82
|
+
// Local function definitions are allowed
|
|
83
|
+
return 'custom implementation'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function Component() {
|
|
87
|
+
const value = useResponsiveValue()
|
|
88
|
+
return <div>{value}</div>
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## When Not To Use It
|
|
93
|
+
|
|
94
|
+
If your project needs to use `useResponsiveValue` from `@primer/react`, you can disable this rule:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
/* eslint primer-react/no-use-responsive-value: "off" */
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Options
|
|
101
|
+
|
|
102
|
+
This rule has no options.
|