Skip to content

Commit ba9bb7b

Browse files
committed
Handle React.createContext [publish]
1 parent 97bdd56 commit ba9bb7b

6 files changed

+57
-44
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.4.14
4+
5+
- Warn if a context is exported alongside a component (fixes #53). Thanks @IgorAufricht!
6+
37
## 0.4.13
48

59
- Support for `react-redux` connect (`export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)`) (fixes #51)

bun.lockb

-56 Bytes
Binary file not shown.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-refresh",
3-
"version": "0.4.13",
3+
"version": "0.4.14",
44
"type": "module",
55
"license": "MIT",
66
"scripts": {
@@ -16,7 +16,7 @@
1616
"eslint": ">=7"
1717
},
1818
"devDependencies": {
19-
"@arnaud-barre/eslint-config": "^5.0.1",
19+
"@arnaud-barre/eslint-config": "^5.1.0",
2020
"@arnaud-barre/tnode": "^0.19.2",
2121
"@types/eslint": "^9.6.1",
2222
"@types/node": "^20.16.13",

src/only-export-components.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ const invalid = [
290290
code: "export const MyComponent = () => {}; export const MyContext = createContext('test');",
291291
errorId: "reactContext",
292292
},
293+
{
294+
name: "Component and React Context with React import",
295+
code: "export const MyComponent = () => {}; export const MyContext = React.createContext('test');",
296+
errorId: "reactContext",
297+
},
293298
];
294299

295300
const it = (name: string, cases: Parameters<typeof ruleTester.run>[2]) => {

src/only-export-components.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ export const onlyExportComponents: TSESLint.RuleModule<
131131
if (
132132
init &&
133133
init.type === "CallExpression" &&
134-
init.callee.type === "Identifier" &&
135-
init.callee.name === "createContext"
134+
// createContext || React.createContext
135+
((init.callee.type === "Identifier" &&
136+
init.callee.name === "createContext") ||
137+
(init.callee.type === "MemberExpression" &&
138+
init.callee.property.type === "Identifier" &&
139+
init.callee.property.name === "createContext"))
136140
) {
137141
reactContextExports.push(identifierNode);
138142
return;

yarn.lock

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
22
# yarn lockfile v1
3-
# bun ./bun.lockb --hash: 1F972E6107051BEA-6909aeba8da2a8c5-C94D958FE35E68A3-aa62a9f8883caa9e
3+
# bun ./bun.lockb --hash: 0E2E8C648B832E19-f03f14fd57c82352-DE4F31B62A420BFD-c372ca07548ab99e
44

55

6-
"@arnaud-barre/eslint-config@^5.0.1":
7-
version "5.0.1"
8-
resolved "https://registry.npmjs.org/@arnaud-barre/eslint-config/-/eslint-config-5.0.1.tgz"
9-
integrity sha512-x6X0i6o+n/AYFMudTOlctxYmSiAPk9ALXsjWa+/ObEemoUziq/78nmYUfvamuMLd/xKcx4ZaMc9uLoBL7nqpag==
6+
"@arnaud-barre/eslint-config@^5.1.0":
7+
version "5.1.0"
8+
resolved "https://registry.npmjs.org/@arnaud-barre/eslint-config/-/eslint-config-5.1.0.tgz"
9+
integrity sha512-eTkCRiCD+xNgAe24XwxZ/Gx7lGjnXsSKfXWe7eQlewYL0unxSUcGPs/RCJTVCOZoPZ/UacvaBaslOIvB+r1paQ==
1010
dependencies:
1111
confusing-browser-globals "^1.0.11"
12-
eslint-plugin-react-hooks "^5.1.0-rc.0"
13-
eslint-plugin-react-refresh "^0.4.12"
14-
eslint-plugin-unicorn "^55.0.0"
15-
globals "^15.9.0"
16-
typescript-eslint "^8.8.0"
12+
eslint-plugin-react-hooks "^5.0.0"
13+
eslint-plugin-react-refresh "^0.4.13"
14+
eslint-plugin-unicorn "^56.0.0"
15+
globals "^15.11.0"
16+
typescript-eslint "^8.10.0"
1717

1818
"@arnaud-barre/tnode@^0.19.2":
1919
version "0.19.2"
@@ -30,7 +30,7 @@
3030
"@babel/highlight" "^7.25.7"
3131
picocolors "^1.0.0"
3232

33-
"@babel/helper-validator-identifier@^7.24.5", "@babel/helper-validator-identifier@^7.25.7":
33+
"@babel/helper-validator-identifier@^7.24.7", "@babel/helper-validator-identifier@^7.25.7":
3434
version "7.25.7"
3535
resolved "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.7.tgz"
3636
integrity sha512-AM6TzwYqGChO45oiuPqwL2t20/HdMC1rTPAesnBCgPCSF1x3oN9MVUwQV2iyz4xqWrctwK5RNC8LV22kaQCNYg==
@@ -549,7 +549,7 @@ confusing-browser-globals@^1.0.11:
549549
resolved "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz"
550550
integrity sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==
551551

552-
core-js-compat@^3.37.0:
552+
core-js-compat@^3.38.1:
553553
version "3.38.1"
554554
resolved "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.38.1.tgz"
555555
integrity sha512-JRH6gfXxGmrzF3tZ57lFx97YARxCXPaMzPo6jELZhv88pBH5VXpQ+y0znKGlFnzuaihqhLbefxSJxWJMPtfDzw==
@@ -633,7 +633,7 @@ escape-string-regexp@^4.0.0:
633633
resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz"
634634
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
635635

636-
eslint@>=7, eslint@>=8.56.0, "eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0", "eslint@^6.0.0 || ^7.0.0 || >=8.0.0", "eslint@^8.57.0 || ^9.0.0", eslint@^9.13.0, eslint@^9.9.1:
636+
eslint@>=7, eslint@>=8.56.0, "eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0", "eslint@^6.0.0 || ^7.0.0 || >=8.0.0", "eslint@^8.57.0 || ^9.0.0", eslint@^9.13.0:
637637
version "9.13.0"
638638
resolved "https://registry.npmjs.org/eslint/-/eslint-9.13.0.tgz"
639639
integrity sha512-EYZK6SX6zjFHST/HRytOdA/zE72Cq/bfw45LSyuwrdvcclb/gqV8RRQxywOBEWO2+WDpva6UZa4CcDeJKzUCFA==
@@ -674,37 +674,37 @@ eslint@>=7, eslint@>=8.56.0, "eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.
674674
optionator "^0.9.3"
675675
text-table "^0.2.0"
676676

677-
"eslint-plugin-react-hooks@^5.1.0-rc.0":
678-
version "5.1.0-rc-fb9a90fa48-20240614"
679-
resolved "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-5.1.0-rc-fb9a90fa48-20240614.tgz"
680-
integrity sha512-xsiRwaDNF5wWNC4ZHLut+x/YcAxksUd9Rizt7LaEn3bV8VyYRpXnRJQlLOfYaVy9esk4DFP4zPPnoNVjq5Gc0w==
677+
eslint-plugin-react-hooks@^5.0.0:
678+
version "5.0.0"
679+
resolved "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-5.0.0.tgz"
680+
integrity sha512-hIOwI+5hYGpJEc4uPRmz2ulCjAGD/N13Lukkh8cLV0i2IRk/bdZDYjgLVHj+U9Z704kLIdIO6iueGvxNur0sgw==
681681

682-
eslint-plugin-react-refresh@^0.4.12:
683-
version "0.4.12"
684-
resolved "https://registry.npmjs.org/eslint-plugin-react-refresh/-/eslint-plugin-react-refresh-0.4.12.tgz"
685-
integrity sha512-9neVjoGv20FwYtCP6CB1dzR1vr57ZDNOXst21wd2xJ/cTlM2xLq0GWVlSNTdMn/4BtP6cHYBMCSp1wFBJ9jBsg==
682+
eslint-plugin-react-refresh@^0.4.13:
683+
version "0.4.13"
684+
resolved "https://registry.npmjs.org/eslint-plugin-react-refresh/-/eslint-plugin-react-refresh-0.4.13.tgz"
685+
integrity sha512-f1EppwrpJRWmqDTyvAyomFVDYRtrS7iTEqv3nokETnMiMzs2SSTmKRTACce4O2p4jYyowiSMvpdwC/RLcMFhuQ==
686686

687-
eslint-plugin-unicorn@^55.0.0:
688-
version "55.0.0"
689-
resolved "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-55.0.0.tgz"
690-
integrity sha512-n3AKiVpY2/uDcGrS3+QsYDkjPfaOrNrsfQxU9nt5nitd9KuvVXrfAvgCO9DYPSfap+Gqjw9EOrXIsBp5tlHZjA==
687+
eslint-plugin-unicorn@^56.0.0:
688+
version "56.0.0"
689+
resolved "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-56.0.0.tgz"
690+
integrity sha512-aXpddVz/PQMmd69uxO98PA4iidiVNvA0xOtbpUoz1WhBd4RxOQQYqN618v68drY0hmy5uU2jy1bheKEVWBjlPw==
691691
dependencies:
692-
jsesc "^3.0.2"
693-
semver "^7.6.1"
692+
"@babel/helper-validator-identifier" "^7.24.7"
693+
"@eslint-community/eslint-utils" "^4.4.0"
694694
ci-info "^4.0.0"
695-
esquery "^1.5.0"
696-
globals "^15.7.0"
695+
clean-regexp "^1.0.0"
696+
core-js-compat "^3.38.1"
697+
esquery "^1.6.0"
698+
globals "^15.9.0"
699+
indent-string "^4.0.0"
700+
is-builtin-module "^3.2.1"
701+
jsesc "^3.0.2"
697702
pluralize "^8.0.0"
698703
read-pkg-up "^7.0.1"
699704
regexp-tree "^0.1.27"
700705
regjsparser "^0.10.0"
701-
clean-regexp "^1.0.0"
706+
semver "^7.6.3"
702707
strip-indent "^3.0.0"
703-
indent-string "^4.0.0"
704-
core-js-compat "^3.37.0"
705-
is-builtin-module "^3.2.1"
706-
"@eslint-community/eslint-utils" "^4.4.0"
707-
"@babel/helper-validator-identifier" "^7.24.5"
708708

709709
eslint-scope@^8.1.0:
710710
version "8.1.0"
@@ -733,7 +733,7 @@ espree@^10.0.1, espree@^10.2.0:
733733
acorn-jsx "^5.3.2"
734734
eslint-visitor-keys "^4.1.0"
735735

736-
esquery@^1.5.0:
736+
esquery@^1.5.0, esquery@^1.6.0:
737737
version "1.6.0"
738738
resolved "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz"
739739
integrity sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==
@@ -857,7 +857,7 @@ globals@^14.0.0:
857857
resolved "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz"
858858
integrity sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==
859859

860-
globals@^15.7.0, globals@^15.9.0:
860+
globals@^15.11.0, globals@^15.9.0:
861861
version "15.11.0"
862862
resolved "https://registry.npmjs.org/globals/-/globals-15.11.0.tgz"
863863
integrity sha512-yeyNSjdbyVaWurlwCpcA6XNBrHTMIeDdj0/hnvX/OLJ9ekOXYbLsLinH/MucQyGvNnXhidTdNhTtJaffL2sMfw==
@@ -1265,7 +1265,7 @@ run-parallel@^1.1.9:
12651265
resolved "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz"
12661266
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==
12671267

1268-
semver@^7.6.0, semver@^7.6.1:
1268+
semver@^7.6.0, semver@^7.6.3:
12691269
version "7.6.3"
12701270
resolved "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz"
12711271
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==
@@ -1373,12 +1373,12 @@ type-fest@^0.8.1:
13731373
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz"
13741374
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==
13751375

1376-
typescript@>=4.2.0, typescript@~5.5.4, typescript@~5.6:
1376+
typescript@>=4.2.0, typescript@~5.6:
13771377
version "5.6.3"
13781378
resolved "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz"
13791379
integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==
13801380

1381-
typescript-eslint@^8.8.0:
1381+
typescript-eslint@^8.10.0:
13821382
version "8.10.0"
13831383
resolved "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.10.0.tgz"
13841384
integrity sha512-YIu230PeN7z9zpu/EtqCIuRVHPs4iSlqW6TEvjbyDAE3MZsSl2RXBo+5ag+lbABCG8sFM1WVKEXhlQ8Ml8A3Fw==

0 commit comments

Comments
 (0)