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

[Bug]: react/jsx-no-literals crashes with Cannot read properties of null (reading 'type') #3822

Closed
2 tasks done
reosarevok opened this issue Sep 12, 2024 · 1 comment
Closed
2 tasks done
Labels

Comments

@reosarevok
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Trying the latest v7.36.0 version of the plugin, we're seeing crashes such as:

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError: Cannot read properties of null (reading 'type')
Occurred while linting /home/reosarevok/musicbrainz-server/root/annotation/AnnotationHistory.js:32
Rule: "react/jsx-no-literals"
    at JSXAttribute (/home/reosarevok/musicbrainz-server/node_modules/eslint-plugin-react/lib/rules/jsx-no-literals.js:508:44)
    at ruleErrorHandler (/home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
    at /home/reosarevok/musicbrainz-server/node_modules/eslint/lib/linter/linter.js:1111:32

That specific line is fullWidth in

    <LayoutComponent
      entity={entity}
      fullWidth
      page="annotation-history"
      title={l('Annotation history')}
    >

The failure seems to be due to b8217ed removing the node && node.value && checks from the new isLiteralString and isStringLiteral calculations, which were present in the previous isNodeValueString. Just changing both those checks to do node.value?.type fixes the issue, and it seems like it should be safe, but you might want to make sure (happy to send a PR if that's the case).

Expected Behavior

The plugin should not crash and should understand there's no issue with this code.

eslint-plugin-react version

v7.36.0

eslint version

v8.57.0

node version

v22.8.0

@reosarevok reosarevok added the bug label Sep 12, 2024
@reosarevok
Copy link
Contributor Author

reosarevok commented Sep 12, 2024

Seems this got reported while I was writing it, so this is a duplicate of #3820 :)

@reosarevok reosarevok closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant