Skip to content

Commit ce25b89

Browse files
authored
fix: Add react-refresh/only-export-components support and fix eslint-plugin-n rule aliases (#342)
* Add a snapshot test for the result from using the react-refresh plugin. * Disallow react-refresh as a JS Plugin in the migrator, as we support its only rule natively. * Update comment. * Add comment. * fix: Add `react-refresh/only-export-components` to the generated rules list. I still need to implement the logic for renaming it back to just `react/` elsewhere, but this is necessary for the rule to be recognized as a supported rule. I should probably also make the same change to `eslint-plugin-oxlint` later. * Fix the node plugin name for the generated rules list. This ensures that we can correctly match eslint-plugin-n rules when migrating :) Need to port this change to eslint-plugin-oxlint as well. * Set up the react-reflesh plugin name swap logic. Now it correctly sets the rule scope to just `react/` :) * Fix typecheck.
1 parent 5eca4cd commit ce25b89

File tree

11 files changed

+242
-29
lines changed

11 files changed

+242
-29
lines changed

integration_test/__snapshots__/autoprefixer.spec.ts.snap

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,21 @@ exports[`autoprefixer > autoprefixer 1`] = `
2727
],
2828
"rules": {
2929
"no-unused-expressions": "off",
30+
"node/global-require": "off",
31+
},
32+
},
33+
{
34+
"files": [
35+
"bin/autoprefixer",
36+
],
37+
"rules": {
38+
"node/global-require": "off",
3039
},
3140
},
3241
],
3342
"plugins": [
3443
"import",
44+
"node",
3545
"promise",
3646
],
3747
"rules": {
@@ -206,6 +216,9 @@ exports[`autoprefixer > autoprefixer 1`] = `
206216
"no-var": "warn",
207217
"no-void": "error",
208218
"no-with": "error",
219+
"node/global-require": "error",
220+
"node/no-exports-assign": "error",
221+
"node/no-new-require": "error",
209222
"prefer-exponentiation-operator": "error",
210223
"prefer-promise-reject-errors": "error",
211224
"prefer-rest-params": "error",
@@ -267,13 +280,10 @@ exports[`autoprefixer > autoprefixer 1`] = `
267280
"camelcase",
268281
"dot-notation",
269282
"func-name-matching",
270-
"n/global-require",
271283
"n/handle-callback-err",
272284
"n/no-deprecated-api",
273-
"n/no-exports-assign",
274285
"n/no-extraneous-require",
275286
"n/no-missing-require",
276-
"n/no-new-require",
277287
"n/no-path-concat",
278288
"n/no-unpublished-require",
279289
"n/no-unsupported-features/es-builtins",
@@ -324,13 +334,10 @@ exports[`autoprefixer > autoprefixer 1`] = `
324334
"unsupported rule: func-name-matching",
325335
"unsupported rule, but available as a nursery rule: getter-return",
326336
"unsupported rule, but available as a nursery rule: import-x/export",
327-
"unsupported rule: n/global-require",
328337
"unsupported rule: n/handle-callback-err",
329338
"unsupported rule: n/no-deprecated-api",
330-
"unsupported rule: n/no-exports-assign",
331339
"unsupported rule: n/no-extraneous-require",
332340
"unsupported rule: n/no-missing-require",
333-
"unsupported rule: n/no-new-require",
334341
"unsupported rule: n/no-path-concat",
335342
"unsupported rule: n/no-unpublished-require",
336343
"unsupported rule: n/no-unsupported-features/es-builtins",
@@ -390,11 +397,21 @@ exports[`autoprefixer --js-plugins > autoprefixer--js-plugins 1`] = `
390397
],
391398
"rules": {
392399
"no-unused-expressions": "off",
400+
"node/global-require": "off",
401+
},
402+
},
403+
{
404+
"files": [
405+
"bin/autoprefixer",
406+
],
407+
"rules": {
408+
"node/global-require": "off",
393409
},
394410
},
395411
],
396412
"plugins": [
397413
"import",
414+
"node",
398415
"promise",
399416
],
400417
"rules": {
@@ -569,6 +586,9 @@ exports[`autoprefixer --js-plugins > autoprefixer--js-plugins 1`] = `
569586
"no-var": "warn",
570587
"no-void": "error",
571588
"no-with": "error",
589+
"node/global-require": "error",
590+
"node/no-exports-assign": "error",
591+
"node/no-new-require": "error",
572592
"perfectionist/sort-array-includes": [
573593
"warn",
574594
{
@@ -774,13 +794,10 @@ exports[`autoprefixer --js-plugins > autoprefixer--js-plugins 1`] = `
774794
"camelcase",
775795
"dot-notation",
776796
"func-name-matching",
777-
"n/global-require",
778797
"n/handle-callback-err",
779798
"n/no-deprecated-api",
780-
"n/no-exports-assign",
781799
"n/no-extraneous-require",
782800
"n/no-missing-require",
783-
"n/no-new-require",
784801
"n/no-path-concat",
785802
"n/no-unpublished-require",
786803
"n/no-unsupported-features/es-builtins",
@@ -809,13 +826,10 @@ exports[`autoprefixer --js-plugins > autoprefixer--js-plugins 1`] = `
809826
"unsupported rule: func-name-matching",
810827
"unsupported rule, but available as a nursery rule: getter-return",
811828
"unsupported rule, but available as a nursery rule: import-x/export",
812-
"unsupported rule: n/global-require",
813829
"unsupported rule: n/handle-callback-err",
814830
"unsupported rule: n/no-deprecated-api",
815-
"unsupported rule: n/no-exports-assign",
816831
"unsupported rule: n/no-extraneous-require",
817832
"unsupported rule: n/no-missing-require",
818-
"unsupported rule: n/no-new-require",
819833
"unsupported rule: n/no-path-concat",
820834
"unsupported rule: n/no-unpublished-require",
821835
"unsupported rule: n/no-unsupported-features/es-builtins",
@@ -870,11 +884,21 @@ exports[`autoprefixer --type-aware > autoprefixer--type-aware 1`] = `
870884
],
871885
"rules": {
872886
"no-unused-expressions": "off",
887+
"node/global-require": "off",
888+
},
889+
},
890+
{
891+
"files": [
892+
"bin/autoprefixer",
893+
],
894+
"rules": {
895+
"node/global-require": "off",
873896
},
874897
},
875898
],
876899
"plugins": [
877900
"import",
901+
"node",
878902
"promise",
879903
],
880904
"rules": {
@@ -1049,6 +1073,9 @@ exports[`autoprefixer --type-aware > autoprefixer--type-aware 1`] = `
10491073
"no-var": "warn",
10501074
"no-void": "error",
10511075
"no-with": "error",
1076+
"node/global-require": "error",
1077+
"node/no-exports-assign": "error",
1078+
"node/no-new-require": "error",
10521079
"prefer-exponentiation-operator": "error",
10531080
"prefer-promise-reject-errors": "error",
10541081
"prefer-rest-params": "error",
@@ -1110,13 +1137,10 @@ exports[`autoprefixer --type-aware > autoprefixer--type-aware 1`] = `
11101137
"camelcase",
11111138
"dot-notation",
11121139
"func-name-matching",
1113-
"n/global-require",
11141140
"n/handle-callback-err",
11151141
"n/no-deprecated-api",
1116-
"n/no-exports-assign",
11171142
"n/no-extraneous-require",
11181143
"n/no-missing-require",
1119-
"n/no-new-require",
11201144
"n/no-path-concat",
11211145
"n/no-unpublished-require",
11221146
"n/no-unsupported-features/es-builtins",
@@ -1167,13 +1191,10 @@ exports[`autoprefixer --type-aware > autoprefixer--type-aware 1`] = `
11671191
"unsupported rule: func-name-matching",
11681192
"unsupported rule, but available as a nursery rule: getter-return",
11691193
"unsupported rule, but available as a nursery rule: import-x/export",
1170-
"unsupported rule: n/global-require",
11711194
"unsupported rule: n/handle-callback-err",
11721195
"unsupported rule: n/no-deprecated-api",
1173-
"unsupported rule: n/no-exports-assign",
11741196
"unsupported rule: n/no-extraneous-require",
11751197
"unsupported rule: n/no-missing-require",
1176-
"unsupported rule: n/no-new-require",
11771198
"unsupported rule: n/no-path-concat",
11781199
"unsupported rule: n/no-unpublished-require",
11791200
"unsupported rule: n/no-unsupported-features/es-builtins",
@@ -1230,11 +1251,21 @@ exports[`autoprefixer merge > autoprefixer--merge 1`] = `
12301251
],
12311252
"rules": {
12321253
"no-unused-expressions": "off",
1254+
"node/global-require": "off",
1255+
},
1256+
},
1257+
{
1258+
"files": [
1259+
"bin/autoprefixer",
1260+
],
1261+
"rules": {
1262+
"node/global-require": "off",
12331263
},
12341264
},
12351265
],
12361266
"plugins": [
12371267
"import",
1268+
"node",
12381269
"promise",
12391270
],
12401271
"rules": {
@@ -1368,6 +1399,9 @@ exports[`autoprefixer merge > autoprefixer--merge 1`] = `
13681399
"no-useless-return": "error",
13691400
"no-var": "warn",
13701401
"no-void": "error",
1402+
"node/global-require": "error",
1403+
"node/no-exports-assign": "error",
1404+
"node/no-new-require": "error",
13711405
"prefer-exponentiation-operator": "error",
13721406
"prefer-promise-reject-errors": "error",
13731407
"prefer-rest-params": "error",
@@ -1428,13 +1462,10 @@ exports[`autoprefixer merge > autoprefixer--merge 1`] = `
14281462
"camelcase",
14291463
"dot-notation",
14301464
"func-name-matching",
1431-
"n/global-require",
14321465
"n/handle-callback-err",
14331466
"n/no-deprecated-api",
1434-
"n/no-exports-assign",
14351467
"n/no-extraneous-require",
14361468
"n/no-missing-require",
1437-
"n/no-new-require",
14381469
"n/no-path-concat",
14391470
"n/no-unpublished-require",
14401471
"n/no-unsupported-features/es-builtins",
@@ -1485,13 +1516,10 @@ exports[`autoprefixer merge > autoprefixer--merge 1`] = `
14851516
"unsupported rule: func-name-matching",
14861517
"unsupported rule, but available as a nursery rule: getter-return",
14871518
"unsupported rule, but available as a nursery rule: import-x/export",
1488-
"unsupported rule: n/global-require",
14891519
"unsupported rule: n/handle-callback-err",
14901520
"unsupported rule: n/no-deprecated-api",
1491-
"unsupported rule: n/no-exports-assign",
14921521
"unsupported rule: n/no-extraneous-require",
14931522
"unsupported rule: n/no-missing-require",
1494-
"unsupported rule: n/no-new-require",
14951523
"unsupported rule: n/no-path-concat",
14961524
"unsupported rule: n/no-unpublished-require",
14971525
"unsupported rule: n/no-unsupported-features/es-builtins",
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`eslint-plugin-react-refresh > eslint-plugin-react-refresh 1`] = `
4+
{
5+
"config": {
6+
"$schema": "./node_modules/oxlint/configuration_schema.json",
7+
"categories": {
8+
"correctness": "off",
9+
},
10+
"env": {
11+
"builtin": true,
12+
},
13+
"plugins": [
14+
"react",
15+
],
16+
"rules": {
17+
"react/only-export-components": "error",
18+
},
19+
},
20+
"skipped": {
21+
"nursery": [],
22+
"type-aware": [],
23+
"unsupported": [],
24+
},
25+
"warnings": [],
26+
}
27+
`;
28+
29+
exports[`eslint-plugin-react-refresh --js-plugins > eslint-plugin-react-refresh--js-plugins 1`] = `
30+
{
31+
"config": {
32+
"$schema": "./node_modules/oxlint/configuration_schema.json",
33+
"categories": {
34+
"correctness": "off",
35+
},
36+
"env": {
37+
"builtin": true,
38+
},
39+
"plugins": [
40+
"react",
41+
],
42+
"rules": {
43+
"react/only-export-components": "error",
44+
},
45+
},
46+
"skipped": {
47+
"nursery": [],
48+
"type-aware": [],
49+
"unsupported": [],
50+
},
51+
"warnings": [],
52+
}
53+
`;
54+
55+
exports[`eslint-plugin-react-refresh --type-aware > eslint-plugin-react-refresh--type-aware 1`] = `
56+
{
57+
"config": {
58+
"$schema": "./node_modules/oxlint/configuration_schema.json",
59+
"categories": {
60+
"correctness": "off",
61+
},
62+
"env": {
63+
"builtin": true,
64+
},
65+
"plugins": [
66+
"react",
67+
],
68+
"rules": {
69+
"react/only-export-components": "error",
70+
},
71+
},
72+
"skipped": {
73+
"nursery": [],
74+
"type-aware": [],
75+
"unsupported": [],
76+
},
77+
"warnings": [],
78+
}
79+
`;
80+
81+
exports[`eslint-plugin-react-refresh merge > eslint-plugin-react-refresh--merge 1`] = `
82+
{
83+
"config": {
84+
"$schema": "./node_modules/oxlint/configuration_schema.json",
85+
"categories": {
86+
"correctness": "error",
87+
"perf": "error",
88+
},
89+
"env": {
90+
"builtin": true,
91+
},
92+
"plugins": [
93+
"react",
94+
],
95+
"rules": {
96+
"react/only-export-components": "error",
97+
},
98+
},
99+
"skipped": {
100+
"nursery": [],
101+
"type-aware": [],
102+
"unsupported": [],
103+
},
104+
"warnings": [],
105+
}
106+
`;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import react_refresh_test from './projects/eslint-plugin-react-refresh.eslint.config.js';
2+
import { testProject } from './utils.js';
3+
4+
testProject('eslint-plugin-react-refresh', react_refresh_test);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from 'eslint/config';
2+
import reactRefresh from 'eslint-plugin-react-refresh';
3+
4+
// This should result in an oxlint config with `react/only-export-components` enabled.
5+
export default defineConfig(reactRefresh.configs.recommended);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"eslint-plugin-react": "^7.37.5",
6868
"eslint-plugin-react-hooks": "^7.0.1",
6969
"eslint-plugin-react-perf": "^3.3.3",
70+
"eslint-plugin-react-refresh": "^0.4.26",
7071
"eslint-plugin-regexp": "^2.9.0",
7172
"eslint-plugin-tsdoc": "^0.5.0",
7273
"eslint-plugin-unicorn": "^62.0.0",

0 commit comments

Comments
 (0)