Skip to content

fix: Add support for component syntax to code-path-analyzer #19875

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akawrykow
Copy link

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

This change updates code-path-analyzer to support component syntax, which is the primary method of writing React components at Meta.

In particular, any rules which rely on onCodePathStart / onCodePathEnd don't trigger correctly when using component syntax.

For example, given the following components:

export component ComponentWithUnreachableLoop() {
  for (let i = 0; i < 100; i++) {
    break;
  }
  return null;
}

export component ComponentWithFunctionWithUnreachableLoop() {
  function loop() {
    for (let i = 0; i < 100; i++) {
      break;
    }
  }
  loop();
  return null;
}

the no-unreachable-loop rule would only trigger on the 2nd component, but not the first one. This is because, for the first component, the start of the component's body is represented by a ComponentDeclaration node and so currently nothing is starting a new code path nor ending a code path. In the 2nd case, it triggers correctly because we have an additional function wrapper, and so the FunctionDeclaration properly begins and ends the code path.

With the changes from this PR, the first component now properly triggers the lint warning:
image

Is there anything you'd like reviewers to focus on?

@akawrykow akawrykow requested a review from a team as a code owner June 19, 2025 13:20
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jun 19, 2025
Copy link

linux-foundation-easycla bot commented Jun 19, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@eslint-github-bot
Copy link

Hi @akawrykow!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@github-actions github-actions bot added the core Relates to ESLint's core APIs and features label Jun 19, 2025
Copy link

netlify bot commented Jun 19, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 9a338e1
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/68540eb076741200080ddebb

@akawrykow akawrykow changed the title Add support for component syntax to code-path-analyzer fix: Add support for component syntax to code-path-analyzer Jun 19, 2025
@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label Jun 19, 2025
@nzakas
Copy link
Member

nzakas commented Jun 19, 2025

Thanks for the PR. Because this isn't a bug fix but rather a feature, it needs to go through our review process. Please open an issue describing the problem you're facing and the solution so the team can review and decide if we want to support this.

As a note: We generally do not add framework-specific functionality into the core.

@nzakas nzakas marked this pull request as draft June 19, 2025 14:58
@nzakas nzakas moved this from Needs Triage to Blocked in Triage Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
Status: Blocked
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy