Skip to content

Conversation

@Rel1cx
Copy link
Owner

@Rel1cx Rel1cx commented Sep 8, 2025

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • Test
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • I have added a convincing reason for adding this feature, if necessary

Other information

@Rel1cx Rel1cx marked this pull request as ready for review September 8, 2025 10:13
@vercel
Copy link

vercel bot commented Sep 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
eslint-react Building Building Preview Comment Sep 8, 2025 10:13am

@Rel1cx Rel1cx requested a review from Copilot September 8, 2025 10:13
@Rel1cx Rel1cx merged commit 2317a46 into 2.0.0 Sep 8, 2025
8 of 9 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a scope checking issue in the no-unnecessary-key ESLint rule to prevent false positives when key props are used in nested components within map callbacks.

  • Adds scope verification to ensure key props are only flagged when they're in the same scope as the map callback
  • Improves the early return optimization by using context.sourceCode.text instead of getText()
  • Adds test coverage for nested component scenarios within map callbacks

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
no-unnecessary-key.ts Adds scope checking logic and optimizes early return condition
no-unnecessary-key.spec.ts Adds test case for nested component scenario

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const initialScope = context.sourceCode.getScope(jsxElement);
const pMapCallback = AST.findParentNode(jsxElement, isMapCallback);
if (pMapCallback == null) return;
if (pMapCallback == null || context.sourceCode.getScope(pMapCallback) !== initialScope) return;
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The scope comparison logic could be clearer. Consider extracting this into a separate variable or adding a comment explaining why scope equality is checked to prevent false positives in nested components.

Suggested change
if (pMapCallback == null || context.sourceCode.getScope(pMapCallback) !== initialScope) return;
// Ensure the map callback is in the same scope as the JSX element to prevent false positives in nested components
const isSameScope = pMapCallback != null && context.sourceCode.getScope(pMapCallback) === initialScope;
if (!isSameScope) return;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants