File tree 4 files changed +17
-5
lines changed
4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ module.exports = {
104
104
function containsWhitespaceExpression ( child ) {
105
105
if ( child . type === 'JSXExpressionContainer' ) {
106
106
const value = child . expression . value ;
107
- return value ? ! ( / \S / . test ( value ) ) : false ;
107
+ return value ? jsxUtil . isWhiteSpaces ( value ) : false ;
108
108
}
109
109
return false ;
110
110
}
@@ -206,7 +206,7 @@ module.exports = {
206
206
}
207
207
208
208
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 ) ;
210
210
}
211
211
212
212
function getAdjacentSiblings ( node , children ) {
Original file line number Diff line number Diff line change 6
6
'use strict' ;
7
7
8
8
const docsUrl = require ( '../util/docsUrl' ) ;
9
+ const jsxUtil = require ( '../util/jsx' ) ;
9
10
10
11
// ------------------------------------------------------------------------------
11
12
// Rule Definition
@@ -89,7 +90,7 @@ module.exports = {
89
90
let countNewLinesAfterContent = 0 ;
90
91
91
92
if ( child . type === 'Literal' || child . type === 'JSXText' ) {
92
- if ( / ^ \s * $ / . test ( child . raw ) ) {
93
+ if ( jsxUtil . isWhiteSpaces ( child . raw ) ) {
93
94
return ;
94
95
}
95
96
Original file line number Diff line number Diff line change 6
6
'use strict' ;
7
7
8
8
const variableUtil = require ( '../util/variable' ) ;
9
+ const jsxUtil = require ( '../util/jsx' ) ;
9
10
const docsUrl = require ( '../util/docsUrl' ) ;
10
11
11
12
// ------------------------------------------------------------------------------
@@ -81,7 +82,7 @@ module.exports = {
81
82
function isLineBreak ( node ) {
82
83
const isLiteral = node . type === 'Literal' || node . type === 'JSXText' ;
83
84
const isMultiline = node . loc . start . line !== node . loc . end . line ;
84
- const isWhiteSpaces = / ^ \s * $ / . test ( node . value ) ;
85
+ const isWhiteSpaces = jsxUtil . isWhiteSpaces ( node . value ) ;
85
86
86
87
return isLiteral && isMultiline && isWhiteSpaces ;
87
88
}
Original file line number Diff line number Diff line change @@ -76,9 +76,19 @@ function isJSXAttributeKey(node) {
76
76
node . name . name === 'key' ;
77
77
}
78
78
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
+
79
88
module . exports = {
80
89
isDOMComponent,
81
90
isFragment,
82
91
isJSX,
83
- isJSXAttributeKey
92
+ isJSXAttributeKey,
93
+ isWhiteSpaces
84
94
} ;
You can’t perform that action at this time.
0 commit comments