Skip to content

Commit 496faa5

Browse files
authored
Fix null error in no-single-element-style-arrays
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.
1 parent 2fa23e2 commit 496faa5

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/rules/no-single-element-style-arrays.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = {
3737
return {
3838
JSXAttribute(node) {
3939
if (node.name.name !== 'style') return;
40+
if (!node.value) return;
4041
if (!node.value.expression) return;
4142
if (node.value.expression.type !== 'ArrayExpression') return;
4243
if (node.value.expression.elements.length === 1) {

0 commit comments

Comments
 (0)