Skip to content

Commit

Permalink
use find() instead of recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
justmejulian committed Nov 18, 2022
1 parent 6f5eacc commit 34a9d4f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 10 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added lib/.DS_Store
Binary file not shown.
14 changes: 4 additions & 10 deletions lib/rules/jsx-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,9 @@ module.exports = {
return /^\s*{\/\*/.test(elementRawValue);
}

function findFirstNonBlockComment(index, elements) {
if (index >= elements.length) return;

const element = elements[index];
const isElementJSX = element.type === 'JSXElement' || element.type === 'JSXExpressionContainer';

if (!isBlockCommentInCurlyBraces(element) && isElementJSX) return element;

return findFirstNonBlockComment(index + 1, elements);
function findFirstNonBlockComment(startIndex, elements) {
const remainingElements = elements.slice(startIndex);
return remainingElements.find((element) => !isBlockCommentInCurlyBraces(element) && (element.type === 'JSXElement' || element.type === 'JSXExpressionContainer'));
}

return {
Expand Down Expand Up @@ -116,8 +110,8 @@ module.exports = {
&& (
isMultilined(element)
|| isMultilined(findFirstNonBlockComment(index + 2, elements)
)
)
)
) {
if (!isWithoutNewLine) return;

Expand Down
Binary file added tests/.DS_Store
Binary file not shown.
Binary file added tests/lib/.DS_Store
Binary file not shown.

0 comments on commit 34a9d4f

Please sign in to comment.