@@ -22,6 +22,13 @@ module.exports = {
2222 } ,
2323
2424 create : function ( context ) {
25+ /**
26+ * @param {object } node An Identifier node
27+ */
28+ function isNonNullaryLiteral ( expression ) {
29+ return expression . type === 'Literal' && expression . value !== null ;
30+ }
31+
2532 /**
2633 * @param {object } node A Identifier node
2734 */
@@ -34,7 +41,7 @@ module.exports = {
3441 return ;
3542 }
3643
37- if ( variable . defs [ 0 ] . node . init . type === 'Literal' ) {
44+ if ( isNonNullaryLiteral ( variable . defs [ 0 ] . node . init ) ) {
3845 context . report ( node , 'Style prop value must be an object' ) ;
3946 }
4047 }
@@ -54,7 +61,7 @@ module.exports = {
5461 if ( style ) {
5562 if ( style . value . type === 'Identifier' ) {
5663 checkIdentifiers ( style . value ) ;
57- } else if ( style . value . type === 'Literal' && style . value . value !== null ) {
64+ } else if ( isNonNullaryLiteral ( style . value ) ) {
5865 context . report ( style . value , 'Style prop value must be an object' ) ;
5966 }
6067 }
@@ -67,10 +74,7 @@ module.exports = {
6774 return ;
6875 }
6976
70- if (
71- node . value . type !== 'JSXExpressionContainer'
72- || ( node . value . expression . type === 'Literal' && node . value . expression . value !== null )
73- ) {
77+ if ( node . value . type !== 'JSXExpressionContainer' || isNonNullaryLiteral ( node . value . expression ) ) {
7478 context . report ( node , 'Style prop value must be an object' ) ;
7579 } else if ( node . value . expression . type === 'Identifier' ) {
7680 checkIdentifiers ( node . value . expression ) ;
0 commit comments