Skip to content

Commit

Permalink
Handle React.createContext [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Oct 24, 2024
1 parent 97bdd56 commit ba9bb7b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.4.14

- Warn if a context is exported alongside a component (fixes #53). Thanks @IgorAufricht!

## 0.4.13

- Support for `react-redux` connect (`export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)`) (fixes #51)
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-react-refresh",
"version": "0.4.13",
"version": "0.4.14",
"type": "module",
"license": "MIT",
"scripts": {
Expand All @@ -16,7 +16,7 @@
"eslint": ">=7"
},
"devDependencies": {
"@arnaud-barre/eslint-config": "^5.0.1",
"@arnaud-barre/eslint-config": "^5.1.0",
"@arnaud-barre/tnode": "^0.19.2",
"@types/eslint": "^9.6.1",
"@types/node": "^20.16.13",
Expand Down
5 changes: 5 additions & 0 deletions src/only-export-components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ const invalid = [
code: "export const MyComponent = () => {}; export const MyContext = createContext('test');",
errorId: "reactContext",
},
{
name: "Component and React Context with React import",
code: "export const MyComponent = () => {}; export const MyContext = React.createContext('test');",
errorId: "reactContext",
},
];

const it = (name: string, cases: Parameters<typeof ruleTester.run>[2]) => {
Expand Down
8 changes: 6 additions & 2 deletions src/only-export-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ export const onlyExportComponents: TSESLint.RuleModule<
if (
init &&
init.type === "CallExpression" &&
init.callee.type === "Identifier" &&
init.callee.name === "createContext"
// createContext || React.createContext
((init.callee.type === "Identifier" &&
init.callee.name === "createContext") ||
(init.callee.type === "MemberExpression" &&
init.callee.property.type === "Identifier" &&
init.callee.property.name === "createContext"))
) {
reactContextExports.push(identifierNode);
return;
Expand Down
80 changes: 40 additions & 40 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# bun ./bun.lockb --hash: 1F972E6107051BEA-6909aeba8da2a8c5-C94D958FE35E68A3-aa62a9f8883caa9e
# bun ./bun.lockb --hash: 0E2E8C648B832E19-f03f14fd57c82352-DE4F31B62A420BFD-c372ca07548ab99e


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

"@arnaud-barre/tnode@^0.19.2":
version "0.19.2"
Expand All @@ -30,7 +30,7 @@
"@babel/highlight" "^7.25.7"
picocolors "^1.0.0"

"@babel/helper-validator-identifier@^7.24.5", "@babel/helper-validator-identifier@^7.25.7":
"@babel/helper-validator-identifier@^7.24.7", "@babel/helper-validator-identifier@^7.25.7":
version "7.25.7"
resolved "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.7.tgz"
integrity sha512-AM6TzwYqGChO45oiuPqwL2t20/HdMC1rTPAesnBCgPCSF1x3oN9MVUwQV2iyz4xqWrctwK5RNC8LV22kaQCNYg==
Expand Down Expand Up @@ -549,7 +549,7 @@ confusing-browser-globals@^1.0.11:
resolved "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz"
integrity sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==

core-js-compat@^3.37.0:
core-js-compat@^3.38.1:
version "3.38.1"
resolved "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.38.1.tgz"
integrity sha512-JRH6gfXxGmrzF3tZ57lFx97YARxCXPaMzPo6jELZhv88pBH5VXpQ+y0znKGlFnzuaihqhLbefxSJxWJMPtfDzw==
Expand Down Expand Up @@ -633,7 +633,7 @@ escape-string-regexp@^4.0.0:
resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz"
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==

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:
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:
version "9.13.0"
resolved "https://registry.npmjs.org/eslint/-/eslint-9.13.0.tgz"
integrity sha512-EYZK6SX6zjFHST/HRytOdA/zE72Cq/bfw45LSyuwrdvcclb/gqV8RRQxywOBEWO2+WDpva6UZa4CcDeJKzUCFA==
Expand Down Expand Up @@ -674,37 +674,37 @@ eslint@>=7, eslint@>=8.56.0, "eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.
optionator "^0.9.3"
text-table "^0.2.0"

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

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

eslint-plugin-unicorn@^55.0.0:
version "55.0.0"
resolved "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-55.0.0.tgz"
integrity sha512-n3AKiVpY2/uDcGrS3+QsYDkjPfaOrNrsfQxU9nt5nitd9KuvVXrfAvgCO9DYPSfap+Gqjw9EOrXIsBp5tlHZjA==
eslint-plugin-unicorn@^56.0.0:
version "56.0.0"
resolved "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-56.0.0.tgz"
integrity sha512-aXpddVz/PQMmd69uxO98PA4iidiVNvA0xOtbpUoz1WhBd4RxOQQYqN618v68drY0hmy5uU2jy1bheKEVWBjlPw==
dependencies:
jsesc "^3.0.2"
semver "^7.6.1"
"@babel/helper-validator-identifier" "^7.24.7"
"@eslint-community/eslint-utils" "^4.4.0"
ci-info "^4.0.0"
esquery "^1.5.0"
globals "^15.7.0"
clean-regexp "^1.0.0"
core-js-compat "^3.38.1"
esquery "^1.6.0"
globals "^15.9.0"
indent-string "^4.0.0"
is-builtin-module "^3.2.1"
jsesc "^3.0.2"
pluralize "^8.0.0"
read-pkg-up "^7.0.1"
regexp-tree "^0.1.27"
regjsparser "^0.10.0"
clean-regexp "^1.0.0"
semver "^7.6.3"
strip-indent "^3.0.0"
indent-string "^4.0.0"
core-js-compat "^3.37.0"
is-builtin-module "^3.2.1"
"@eslint-community/eslint-utils" "^4.4.0"
"@babel/helper-validator-identifier" "^7.24.5"

eslint-scope@^8.1.0:
version "8.1.0"
Expand Down Expand Up @@ -733,7 +733,7 @@ espree@^10.0.1, espree@^10.2.0:
acorn-jsx "^5.3.2"
eslint-visitor-keys "^4.1.0"

esquery@^1.5.0:
esquery@^1.5.0, esquery@^1.6.0:
version "1.6.0"
resolved "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz"
integrity sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==
Expand Down Expand Up @@ -857,7 +857,7 @@ globals@^14.0.0:
resolved "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz"
integrity sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==

globals@^15.7.0, globals@^15.9.0:
globals@^15.11.0, globals@^15.9.0:
version "15.11.0"
resolved "https://registry.npmjs.org/globals/-/globals-15.11.0.tgz"
integrity sha512-yeyNSjdbyVaWurlwCpcA6XNBrHTMIeDdj0/hnvX/OLJ9ekOXYbLsLinH/MucQyGvNnXhidTdNhTtJaffL2sMfw==
Expand Down Expand Up @@ -1265,7 +1265,7 @@ run-parallel@^1.1.9:
resolved "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==

semver@^7.6.0, semver@^7.6.1:
semver@^7.6.0, semver@^7.6.3:
version "7.6.3"
resolved "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==
Expand Down Expand Up @@ -1373,12 +1373,12 @@ type-fest@^0.8.1:
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz"
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==

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

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

0 comments on commit ba9bb7b

Please sign in to comment.