Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsx-no-constructed-context-values: Cannot read property 'set' of undefined #2894

Closed
AriPerkkio opened this issue Dec 31, 2020 · 0 comments
Closed

Comments

@AriPerkkio
Copy link
Contributor

@AriPerkkio AriPerkkio commented Dec 31, 2020

Hello, jsx-no-constructed-context-values rule seems to crash in certain cases. This issue was spotted by automated CI run - it is not blocking my development or anything. https://github.com/AriPerkkio/eslint-remote-tester/actions/runs/454180745

"eslint-plugin-react": "^7.22.0",
{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "settings": {
    "react": {
      "version": "16.13.1"
    }
  },
  "plugins": ["react"],
  "rules": {
    "react/jsx-no-constructed-context-values": "error"
  }
}

Minimal repro:

The as <type> triggers the crash.

import React from 'react';
import MyContext from './MyContext';

const value = '';

function ContextProvider(props) {
    return (
        <MyContext.Provider value={value as any}>
            {props.children}
        </MyContext.Provider>
    )
}
TypeError: Cannot read property 'set' of undefined
Occurred while linting <text>:140
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:25:41)
Crash reports from real projects

Rule: jsx-no-constructed-context-values

  • Message: Cannot read property 'set' of undefined Occurred while linting <text>:140
  • Path: rishavanand/github-profilinator/src/context/GlobalContextProvider.tsx
  • Link
        shiftField: shiftField,
        changeColumnCount: changeColumnCount,
    };

    return <globalContext.Provider value={globalContextData as GlobalContext}>{props.children}</globalContext.Provider>;
};

const wrapWithProvider = ({ element }: { element: React.ReactChildren }) =>
<Provider>{element}</Provider>;

export default wrapWithProvider;
TypeError: Cannot read property 'set' of undefined
Occurred while linting <text>:140
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:25:41)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:113:14)
    at JSXOpeningElement(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:179:31)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)

Rule: jsx-no-constructed-context-values

  • Message: Cannot read property 'set' of undefined Occurred while linting <text>:28
  • Path: jamesknelson/react-routing-library/src/components/routingProvider.tsx
  • Link
    <RouterProvider
      navigation={navigation}
      request={output.request}
      pendingRequest={output.pendingRequest}>
      <RouterContentContext.Provider value={content}>
        {children === undefined ? <Content /> : children}
      </RouterContentContext.Provider>
    </RouterProvider>
  )
}
TypeError: Cannot read property 'set' of undefined
Occurred while linting <text>:28
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:25:41)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:86:31)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:86:31)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:86:31)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:113:14)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:52:32)
    at JSXOpeningElement(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:179:31)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:38)

Rule: jsx-no-constructed-context-values

  • Message: Cannot read property 'set' of undefined Occurred while linting <text>:25
  • Path: Glue42/core/packages/react-hooks/tests/useGlue.spec.tsx
  • Link
                    result = useGlue<{ id: number }>(callback);
                },
                {
                    wrapper: ({ children }) => (
                        <GlueContext.Provider value={mockedGlue as any}>
                            {children}
                        </GlueContext.Provider>
                    ),
                }
            );
TypeError: Cannot read property 'set' of undefined
Occurred while linting <text>:25
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:25:41)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:113:14)
    at JSXOpeningElement(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:179:31)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)

Rule: jsx-no-constructed-context-values

  • Message: Cannot read property 'set' of undefined Occurred while linting <text>:100
  • Path: commercelayer/commercelayer-react-components/src/components/OrderContainer.tsx
  • Link
        setLocalOrder,
      }),
  }
  return (
    <OrderContext.Provider value={orderValue as OrderState}>
      {children}
    </OrderContext.Provider>
  )
}
TypeError: Cannot read property 'set' of undefined
Occurred while linting <text>:100
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:25:41)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:113:14)
    at JSXOpeningElement(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:179:31)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)

Rule: jsx-no-constructed-context-values

  • Message: Cannot read property 'set' of undefined Occurred while linting <text>:146
  • Path: csound/web-ide/src/components/file-tree/context.tsx
  • Link
            onDragEnd={(result) =>
                dispatch({ type: "handleDrop", payload: result, project })
            }
        >
            <DnDStateContext.Provider value={state as any}>
                <DnDDispatchContext.Provider value={dispatch}>
                    {children}
                </DnDDispatchContext.Provider>
            </DnDStateContext.Provider>
        </DragDropContext>
TypeError: Cannot read property 'set' of undefined
Occurred while linting <text>:146
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:25:41)
    at isConstruction(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:113:14)
    at JSXOpeningElement(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-react/lib/rules/jsx-no-constructed-context-values.js:179:31)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode(/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant