Skip to content

Commit cd3648c

Browse files
committed
use better practices
thanks @lencioni
1 parent 1344f1d commit cd3648c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/rules/jsx-one-expression-per-line.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
let countNewLinesAfterContent = 0;
5353

5454
if (child.type === 'Literal') {
55-
if (child.value.match(/^\s*$/)) {
55+
if (/^\s*$/.test(child.raw)) {
5656
return;
5757
}
5858

@@ -80,8 +80,8 @@ module.exports = {
8080
}
8181
});
8282

83-
Object.keys(childrenGroupedByLine).forEach(line => {
84-
line = parseInt(line, 10);
83+
Object.keys(childrenGroupedByLine).forEach(_line => {
84+
const line = parseInt(_line, 10);
8585
const firstIndex = 0;
8686
const lastIndex = childrenGroupedByLine[line].length - 1;
8787

@@ -107,14 +107,14 @@ module.exports = {
107107
}
108108

109109
function spaceBetweenPrev () {
110-
return (prevChild.type === 'Literal' && prevChild.raw.match(/ $/)) ||
111-
(child.type === 'Literal' && child.raw.match(/^ /)) ||
110+
return (prevChild.type === 'Literal' && / $/.test(prevChild.raw)) ||
111+
(child.type === 'Literal' && /^ /.test(child.raw)) ||
112112
sourceCode.isSpaceBetweenTokens(prevChild, child);
113113
}
114114

115115
function spaceBetweenNext () {
116-
return (nextChild.type === 'Literal' && nextChild.raw.match(/^ /)) ||
117-
(child.type === 'Literal' && child.raw.match(/ $/)) ||
116+
return (nextChild.type === 'Literal' && /^ /.test(nextChild.raw)) ||
117+
(child.type === 'Literal' && / $/.test(child.raw)) ||
118118
sourceCode.isSpaceBetweenTokens(child, nextChild);
119119
}
120120

@@ -125,8 +125,8 @@ module.exports = {
125125
const source = sourceCode.getText(child);
126126
const leadingSpace = !!(prevChild && spaceBetweenPrev());
127127
const trailingSpace = !!(nextChild && spaceBetweenNext());
128-
const leadingNewLine = !!(prevChild);
129-
const trailingNewLine = !!(nextChild);
128+
const leadingNewLine = !!prevChild;
129+
const trailingNewLine = !!nextChild;
130130

131131
const key = nodeKey(child);
132132

0 commit comments

Comments
 (0)