@agilebot/eslint-plugin 0.5.2 → 0.5.3

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.
Files changed (2) hide show
  1. package/dist/index.js +41 -5
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license @agilebot/eslint-plugin v0.5.2
2
+ * @license @agilebot/eslint-plugin v0.5.3
3
3
  *
4
4
  * Copyright (c) Agilebot, Inc. and its affiliates.
5
5
  *
@@ -792,6 +792,14 @@ var reactBetterExhaustiveDeps = {
792
792
  enableDangerousAutofixThisMayCauseInfiniteLoops: {
793
793
  type: 'boolean'
794
794
  },
795
+ customHooks: {
796
+ type: 'object',
797
+ additionalProperties: {
798
+ callbackIndex: {
799
+ type: 'number'
800
+ }
801
+ }
802
+ },
795
803
  staticHooks: {
796
804
  type: 'object',
797
805
  additionalProperties: {
@@ -819,11 +827,13 @@ var reactBetterExhaustiveDeps = {
819
827
  create(context) {
820
828
  const additionalHooks = context.options && context.options[0] && context.options[0].additionalHooks ? new RegExp(context.options[0].additionalHooks) : undefined;
821
829
  const enableDangerousAutofixThisMayCauseInfiniteLoops = context.options && context.options[0] && context.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops || false;
830
+ const customHooks = context.options && context.options[0] && context.options[0].customHooks || {};
822
831
  const staticHooks = context.options && context.options[0] && context.options[0].staticHooks || {};
823
832
  const checkMemoizedVariableIsStatic = context.options && context.options[0] && context.options[0].checkMemoizedVariableIsStatic || false;
824
833
  const options = {
825
834
  additionalHooks,
826
835
  enableDangerousAutofixThisMayCauseInfiniteLoops,
836
+ customHooks,
827
837
  staticHooks,
828
838
  checkMemoizedVariableIsStatic
829
839
  };
@@ -861,10 +871,20 @@ var reactBetterExhaustiveDeps = {
861
871
  }
862
872
  function visitFunctionWithDependencies(node, declaredDependenciesNode, reactiveHook, reactiveHookName, isEffect) {
863
873
  if (isEffect && node.async) {
864
- reportProblem({
865
- node: node,
866
- message: "Effect callbacks are synchronous to prevent race conditions. " + "Put the async function inside:\n\n" + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + "}, [someId]); // Or [] if effect doesn't need props or state\n\n" + 'Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching'
867
- });
874
+ let isCustomHook = false;
875
+ if (options.customHooks) {
876
+ Object.entries(options.customHooks).forEach(([key, customParts]) => {
877
+ if (typeof customParts === 'object' && new RegExp(key).test(reactiveHookName)) {
878
+ isCustomHook = true;
879
+ }
880
+ });
881
+ }
882
+ if (!isCustomHook) {
883
+ reportProblem({
884
+ node: node,
885
+ message: "Effect callbacks are synchronous to prevent race conditions. " + "Put the async function inside:\n\n" + 'useEffect(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n' + ' fetchData();\n' + "}, [someId]); // Or [] if effect doesn't need props or state\n\n" + 'Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching'
886
+ });
887
+ }
868
888
  }
869
889
  const scope = scopeManager.acquire(node);
870
890
  const pureScopes = new Set();
@@ -1904,6 +1924,22 @@ function getReactiveHookCallbackIndex(calleeNode, options) {
1904
1924
  case 'useImperativeHandle':
1905
1925
  return 1;
1906
1926
  default:
1927
+ if (node === calleeNode && options && options.customHooks) {
1928
+ let name;
1929
+ try {
1930
+ name = analyzePropertyChain(node, null);
1931
+ } catch (err) {
1932
+ if (/Unsupported node type/.test(err.message)) {
1933
+ return 0;
1934
+ }
1935
+ throw err;
1936
+ }
1937
+ for (const [key, customParts] of Object.entries(options.customHooks)) {
1938
+ if (typeof customParts === 'object' && typeof customParts.callbackIndex === 'number' && new RegExp(key).test(name)) {
1939
+ return customParts.callbackIndex;
1940
+ }
1941
+ }
1942
+ }
1907
1943
  if (node === calleeNode && options && options.additionalHooks) {
1908
1944
  let name;
1909
1945
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilebot/eslint-plugin",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Agilebot's ESLint plugin",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "eslint-plugin-deprecation": "^3.0.0",
24
24
  "eslint-plugin-react": "^7.35.0",
25
25
  "eslint-plugin-react-hooks": "^4.6.2",
26
- "@agilebot/eslint-utils": "0.5.2"
26
+ "@agilebot/eslint-utils": "0.5.3"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0"