File tree Expand file tree Collapse file tree 4 files changed +17
-5
lines changed
Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ module.exports = {
104104 function containsWhitespaceExpression ( child ) {
105105 if ( child . type === 'JSXExpressionContainer' ) {
106106 const value = child . expression . value ;
107- return value ? ! ( / \S / . test ( value ) ) : false ;
107+ return value ? jsxUtil . isWhiteSpaces ( value ) : false ;
108108 }
109109 return false ;
110110 }
@@ -206,7 +206,7 @@ module.exports = {
206206 }
207207
208208 function isWhiteSpaceLiteral ( node ) {
209- return node . type && node . type === 'Literal' && node . value && ! ( / \S / . test ( node . value ) ) ;
209+ return node . type && node . type === 'Literal' && node . value && jsxUtil . isWhiteSpaces ( node . value ) ;
210210 }
211211
212212 function getAdjacentSiblings ( node , children ) {
Original file line number Diff line number Diff line change 66'use strict' ;
77
88const docsUrl = require ( '../util/docsUrl' ) ;
9+ const jsxUtil = require ( '../util/jsx' ) ;
910
1011// ------------------------------------------------------------------------------
1112// Rule Definition
@@ -89,7 +90,7 @@ module.exports = {
8990 let countNewLinesAfterContent = 0 ;
9091
9192 if ( child . type === 'Literal' || child . type === 'JSXText' ) {
92- if ( / ^ \s * $ / . test ( child . raw ) ) {
93+ if ( jsxUtil . isWhiteSpaces ( child . raw ) ) {
9394 return ;
9495 }
9596
Original file line number Diff line number Diff line change 66'use strict' ;
77
88const variableUtil = require ( '../util/variable' ) ;
9+ const jsxUtil = require ( '../util/jsx' ) ;
910const docsUrl = require ( '../util/docsUrl' ) ;
1011
1112// ------------------------------------------------------------------------------
@@ -81,7 +82,7 @@ module.exports = {
8182 function isLineBreak ( node ) {
8283 const isLiteral = node . type === 'Literal' || node . type === 'JSXText' ;
8384 const isMultiline = node . loc . start . line !== node . loc . end . line ;
84- const isWhiteSpaces = / ^ \s * $ / . test ( node . value ) ;
85+ const isWhiteSpaces = jsxUtil . isWhiteSpaces ( node . value ) ;
8586
8687 return isLiteral && isMultiline && isWhiteSpaces ;
8788 }
Original file line number Diff line number Diff line change @@ -76,9 +76,19 @@ function isJSXAttributeKey(node) {
7676 node . name . name === 'key' ;
7777}
7878
79+ /**
80+ * Check if value has only whitespaces
81+ * @param {string } value
82+ * @returns {boolean }
83+ */
84+ function isWhiteSpaces ( value ) {
85+ return typeof value === 'string' ? / ^ \s * $ / . test ( value ) : false ;
86+ }
87+
7988module . exports = {
8089 isDOMComponent,
8190 isFragment,
8291 isJSX,
83- isJSXAttributeKey
92+ isJSXAttributeKey,
93+ isWhiteSpaces
8494} ;
You can’t perform that action at this time.
0 commit comments