eslint-plugin-primer-react 8.3.0 → 8.4.0-rc.6ac270a
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/check-for-changeset.yml +1 -1
- package/.github/workflows/ci.yml +3 -3
- package/.github/workflows/release.yml +1 -1
- package/.github/workflows/release_canary.yml +1 -1
- package/.github/workflows/release_candidate.yml +1 -1
- package/CHANGELOG.md +6 -0
- package/docs/rules/spread-props-first.md +66 -0
- package/package-lock.json +9922 -0
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/rules/__tests__/spread-props-first.test.js +123 -0
- package/src/rules/spread-props-first.js +81 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -9,7 +9,7 @@ jobs:
|
|
|
9
9
|
format:
|
|
10
10
|
runs-on: ubuntu-latest
|
|
11
11
|
steps:
|
|
12
|
-
- uses: actions/checkout@
|
|
12
|
+
- uses: actions/checkout@v5
|
|
13
13
|
- name: Use Node.js
|
|
14
14
|
uses: actions/setup-node@v4
|
|
15
15
|
with:
|
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
test:
|
|
22
22
|
runs-on: ubuntu-latest
|
|
23
23
|
steps:
|
|
24
|
-
- uses: actions/checkout@
|
|
24
|
+
- uses: actions/checkout@v5
|
|
25
25
|
- name: Use Node.js
|
|
26
26
|
uses: actions/setup-node@v4
|
|
27
27
|
with:
|
|
@@ -33,7 +33,7 @@ jobs:
|
|
|
33
33
|
lint:
|
|
34
34
|
runs-on: ubuntu-latest
|
|
35
35
|
steps:
|
|
36
|
-
- uses: actions/checkout@
|
|
36
|
+
- uses: actions/checkout@v5
|
|
37
37
|
- name: Use Node.js
|
|
38
38
|
uses: actions/setup-node@v4
|
|
39
39
|
with:
|
|
@@ -8,7 +8,7 @@ jobs:
|
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
9
|
steps:
|
|
10
10
|
- name: Checkout repository
|
|
11
|
-
uses: actions/checkout@
|
|
11
|
+
uses: actions/checkout@v5
|
|
12
12
|
with:
|
|
13
13
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
14
14
|
fetch-depth: 0
|
|
@@ -15,7 +15,7 @@ jobs:
|
|
|
15
15
|
runs-on: ubuntu-latest
|
|
16
16
|
steps:
|
|
17
17
|
- name: Checkout repository
|
|
18
|
-
uses: actions/checkout@
|
|
18
|
+
uses: actions/checkout@v5
|
|
19
19
|
with:
|
|
20
20
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
21
21
|
fetch-depth: 0
|
|
@@ -11,7 +11,7 @@ jobs:
|
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
steps:
|
|
13
13
|
- name: Checkout repository
|
|
14
|
-
uses: actions/checkout@
|
|
14
|
+
uses: actions/checkout@v5
|
|
15
15
|
with:
|
|
16
16
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
17
17
|
fetch-depth: 0
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# eslint-plugin-primer-react
|
|
2
2
|
|
|
3
|
+
## 8.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#437](https://github.com/primer/eslint-plugin-primer-react/pull/437) [`9270d40`](https://github.com/primer/eslint-plugin-primer-react/commit/9270d40d73bd046e21156b68ef6bd13a20008585) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Add spread-props-first rule to ensure spread props come before other props
|
|
8
|
+
|
|
3
9
|
## 8.3.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Ensure spread props come before other props (spread-props-first)
|
|
2
|
+
|
|
3
|
+
Spread props should come before other named props to avoid unintentionally overriding props. When spread props are placed after named props, they can override the named props, which is often unintended and can lead to UI bugs.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
This rule enforces that all spread props (`{...rest}`, `{...props}`, etc.) come before any named props in JSX elements.
|
|
8
|
+
|
|
9
|
+
👎 Examples of **incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```jsx
|
|
12
|
+
/* eslint primer-react/spread-props-first: "error" */
|
|
13
|
+
|
|
14
|
+
// ❌ Spread after named prop
|
|
15
|
+
<Example className="..." {...rest} />
|
|
16
|
+
|
|
17
|
+
// ❌ Spread in the middle
|
|
18
|
+
<Example className="..." {...rest} id="foo" />
|
|
19
|
+
|
|
20
|
+
// ❌ Multiple spreads after named props
|
|
21
|
+
<Example className="..." {...rest} {...other} />
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
👍 Examples of **correct** code for this rule:
|
|
25
|
+
|
|
26
|
+
```jsx
|
|
27
|
+
/* eslint primer-react/spread-props-first: "error" */
|
|
28
|
+
|
|
29
|
+
// ✅ Spread before named props
|
|
30
|
+
<Example {...rest} className="..." />
|
|
31
|
+
|
|
32
|
+
// ✅ Multiple spreads before named props
|
|
33
|
+
<Example {...rest} {...other} className="..." />
|
|
34
|
+
|
|
35
|
+
// ✅ Only spread props
|
|
36
|
+
<Example {...rest} />
|
|
37
|
+
|
|
38
|
+
// ✅ Only named props
|
|
39
|
+
<Example className="..." id="foo" />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Why this matters
|
|
43
|
+
|
|
44
|
+
Placing spread props after named props can cause unexpected behavior:
|
|
45
|
+
|
|
46
|
+
```jsx
|
|
47
|
+
// ❌ Bad: className might get overridden by rest
|
|
48
|
+
<Button className="custom-class" {...rest} />
|
|
49
|
+
|
|
50
|
+
// If rest = { className: "other-class" }
|
|
51
|
+
// Result: className="other-class" (custom-class is lost!)
|
|
52
|
+
|
|
53
|
+
// ✅ Good: className will override any className in rest
|
|
54
|
+
<Button {...rest} className="custom-class" />
|
|
55
|
+
|
|
56
|
+
// If rest = { className: "other-class" }
|
|
57
|
+
// Result: className="custom-class" (as intended)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Options
|
|
61
|
+
|
|
62
|
+
This rule has no configuration options.
|
|
63
|
+
|
|
64
|
+
## When to use autofix
|
|
65
|
+
|
|
66
|
+
This rule includes an autofix that will automatically reorder your props to place all spread props first. The autofix is safe to use as it preserves the order of spreads relative to each other and the order of named props relative to each other.
|