Skip to content

Fix null error in no-single-element-style-arrays#290

Open
frw wants to merge 1 commit into
Intellicode:masterfrom
frw:patch-1
Open

Fix null error in no-single-element-style-arrays#290
frw wants to merge 1 commit into
Intellicode:masterfrom
frw:patch-1

Conversation

@frw
Copy link
Copy Markdown

@frw frw commented Jun 15, 2021

I'm using the ESLint plugin in VSCode, and when I'm in the middle of typing out my component style (e.g. <View style>) in VSCode, I'm getting the following error:

TypeError: Cannot read property 'expression' of null
Occurred while linting root\src\Component.tsx:72
    at JSXAttribute (root\node_modules\eslint-plugin-react-native\lib\rules\no-single-element-style-arrays.js:40:25)
    at root\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (root\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (root\node_modules\eslint\lib\linter\node-event-generator.js:293:26)
    at NodeEventGenerator.applySelectors (root\node_modules\eslint\lib\linter\node-event-generator.js:322:22)
    at NodeEventGenerator.enterNode (root\node_modules\eslint\lib\linter\node-event-generator.js:336:14)
    at CodePathAnalyzer.enterNode (root\node_modules\eslint\lib\linter\code-path-analysis\code-path-analyzer.js:711:23)
    at root\node_modules\eslint\lib\linter\linter.js:954:32
    at Array.forEach (<anonymous>)

Although a style attribute with no value is technically not valid, no-single-element-style-arrays should silently ignore this and not throw an error.

I'm using the ESLint plugin in VSCode, and when I'm in the middle of typing out my component style (e.g. `<View style>`) in VSCode, I'm getting the following error:
```
TypeError: Cannot read property 'expression' of null
Occurred while linting D:\Dropbox\Projects\Tokuu\Code\packages\app\src\components\products\AddImageButton.tsx:72
    at JSXAttribute (D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint-plugin-react-native\lib\rules\no-single-element-style-arrays.js:40:25)
    at D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint\lib\linter\node-event-generator.js:293:26)
    at NodeEventGenerator.applySelectors (D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint\lib\linter\node-event-generator.js:322:22)
    at NodeEventGenerator.enterNode (D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint\lib\linter\node-event-generator.js:336:14)
    at CodePathAnalyzer.enterNode (D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint\lib\linter\code-path-analysis\code-path-analyzer.js:711:23)
    at D:\Dropbox\Projects\Tokuu\Code\node_modules\eslint\lib\linter\linter.js:954:32
    at Array.forEach (<anonymous>)
```

Although a style attribute with no value is technically not valid, `no-single-element-style-arrays` should silently ignore this and not throw an error.
@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@frw
Copy link
Copy Markdown
Author

frw commented Oct 19, 2021

Hi @Intellicode, could you take a quick look at this?

Copy link
Copy Markdown

@StantonMatt StantonMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a local pass because this is a small crash fix and the PR branch does not report any hosted checks.

The one-line guard applies cleanly on current origin/master. I verified the reported case with a RuleTester fixture:

  • current origin/master throws Cannot read properties of null (reading 'expression') on <App style>foo</App>
  • the merged patch ignores the missing style value and still reports/fixes the existing single-element array case

I also ran the current-master merge simulation locally:

TMPDIR=.codex-tmp/npm-tmp npm_config_cache=.codex-tmp/npm-cache npm ci
./node_modules/.bin/mocha tests/lib/rules/no-single-element-style-arrays.js
npm test
git diff --check --cached

Those passed: the focused rule file had 8 passing tests, and the full suite had 129 passing tests.

The only thing I would add before merging is a committed regression test for <App style> in tests/lib/rules/no-single-element-style-arrays.js, so this editor/incomplete-JSX case stays covered. Behavior-wise, the fix looks right from this pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants