Skip to content

fix: fixed jsx detection method not respect SkipEmptyArray hint, closes #1122 #1124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/jsx/jsx-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export function isJsxLike(
return !(hint & JSXDetectionHint.SkipStringLiteral);
}
case T.ArrayExpression: {
if (node.elements.length === 0) {
return !(hint & JSXDetectionHint.SkipEmptyArray);
}
if (hint & JSXDetectionHint.StrictArray) {
return node.elements.every((n) => isJsxLike(code, n, hint));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,5 +686,46 @@ ruleTesterWithTypes.run(RULE_NAME, rule, {

export { ItemsListElementSkeleton }
`,
// https://github.com/Rel1cx/eslint-react/issues/1122
tsx`
import { useState } from 'react';

type Book = {
title: string,
author: string,
}
export default function MyComponent() {
const [books, setBooks] = useState<Book[]>([]);
const dropFirstBook = () => {
setBooks(
// Error in next line: A function component's props should be read-only.
// Source: @eslint-react/prefer-read-only-props
(currentBooks: Book[]) => {
const newBooks: Book[] = [];
// Considerable additional logic is found here in a non-toy example;
// suggestions to just rewrite this as e.g.,
// return [...currentBooks.slice(1)];
// which gets the above line reported as compliant with the rule
// are not nearly as helpful as they might seem,
// though knowing about them might help find the root cause of the bug.
newBooks.push(...currentBooks.slice(1));
return newBooks;
}
);
};
//Please assume there's more that was simplified away for this bug demonstration.
if(books.length > 0) {
return(<>
The first book is {books[0].title}.
<button
type='button'
onClick={dropFirstBook}
> Remove it. </button>
</>);
} else {
return null;
}
}
`,
],
});
Loading