Fix null error in no-single-element-style-arrays#290
Conversation
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.
|
Kudos, SonarCloud Quality Gate passed!
|
|
Hi @Intellicode, could you take a quick look at this? |
There was a problem hiding this comment.
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/masterthrowsCannot 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 --cachedThose 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.
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:Although a style attribute with no value is technically not valid,
no-single-element-style-arraysshould silently ignore this and not throw an error.