Skip to content

Commit 34a9d4f

Browse files
committed
use find() instead of recursion
1 parent 6f5eacc commit 34a9d4f

File tree

5 files changed

+4
-10
lines changed

5 files changed

+4
-10
lines changed

.DS_Store

8 KB
Binary file not shown.

lib/.DS_Store

6 KB
Binary file not shown.

lib/rules/jsx-newline.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,9 @@ module.exports = {
7777
return /^\s*{\/\*/.test(elementRawValue);
7878
}
7979

80-
function findFirstNonBlockComment(index, elements) {
81-
if (index >= elements.length) return;
82-
83-
const element = elements[index];
84-
const isElementJSX = element.type === 'JSXElement' || element.type === 'JSXExpressionContainer';
85-
86-
if (!isBlockCommentInCurlyBraces(element) && isElementJSX) return element;
87-
88-
return findFirstNonBlockComment(index + 1, elements);
80+
function findFirstNonBlockComment(startIndex, elements) {
81+
const remainingElements = elements.slice(startIndex);
82+
return remainingElements.find((element) => !isBlockCommentInCurlyBraces(element) && (element.type === 'JSXElement' || element.type === 'JSXExpressionContainer'));
8983
}
9084

9185
return {
@@ -116,8 +110,8 @@ module.exports = {
116110
&& (
117111
isMultilined(element)
118112
|| isMultilined(findFirstNonBlockComment(index + 2, elements)
113+
)
119114
)
120-
)
121115
) {
122116
if (!isWithoutNewLine) return;
123117

tests/.DS_Store

6 KB
Binary file not shown.

tests/lib/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)