Skip to content
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

Bug: 5.27.0 regression: @typescript-eslint/no-unused-vars wrongly reports the jsxFactory set in tsconfig.json #5153

Closed
4 tasks done
lydell opened this issue Jun 6, 2022 · 5 comments · Fixed by #6134
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: parser Issues related to @typescript-eslint/parser

Comments

@lydell
Copy link
Contributor

lydell commented Jun 6, 2022

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

I use Preact and have this in my tsconfig.json:

    "jsx": "react",
    "jsxFactory": "h",
    "jsxFragmentFactory": "Fragment"

I use it like so:

import { h, Fragment } from "preact";

export default function MyComponent() {
  return <><h1>Hello, world!</h1></>;
}

It used to result in no errors. With version 5.27.0, it reports h and Fragment as unused.

I’ve searched through the issue tracker, and also in TypeScript’s and Preact’s issue trackers, but couldn’t find anything. I apologize if I missed something, or this is a misunderstanding on my side that just happened to work before!

Reproduction Repository Link

https://github.com/lydell/typescript-eslint-preact-issue

Repro Steps

  1. clone the repo
  2. npm ci
  3. npm test

Versions

package version
@typescript-eslint/eslint-plugin 5.27.0
@typescript-eslint/parser 5.27.0
TypeScript 4.7.3
ESLint 8.17.0
node 18.1.0
@lydell lydell added bug Something isn't working triage Waiting for maintainers to take a look labels Jun 6, 2022
@bradzacher
Copy link
Member

I can check later today when I'm at my laptop, but I think all you need is to set parserOptions.jsx = true

We probably should remove that restriction though as we don't use that anywhere else.

@lydell
Copy link
Contributor Author

lydell commented Jun 6, 2022

I can confirm that adding this to my ESLint config makes it work:

"parserOptions": {
  "ecmaFeatures": {
    "jsx": true
  }
}

@bradzacher bradzacher added enhancement New feature or request package: parser Issues related to @typescript-eslint/parser accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Jun 6, 2022
@bradzacher
Copy link
Member

For this issue we want to remove the requirement for the parserOptions.ecmaFeatures.jsx option to be set for the automated pragma resolution. Should be a simple change!

@bradzacher bradzacher added good first issue Good for newcomers and removed enhancement New feature or request labels Jun 6, 2022
@Solo-steven
Copy link
Contributor

Hi @bradzacher , I am new there and I want to take this issue. After some research, I find two solutions,
The first is to make jsx option fallback to true, which would make the parser automatically resolve jsx pragma.
Screen Shot 2022-11-25 at 6 52 06 PM
Screen Shot 2022-11-25 at 6 53 20 PM

The second solution is to emit the if statement before pragma resolves, but this method would make the parser resolve jsx pragma even if jsx option is false. So I think the first solution is a better one.
Screen Shot 2022-11-25 at 6 54 13 PM

looking forward to your response!

@bradzacher
Copy link
Member

Given that JSX pragma and factory are only used by the tooling if we encounter JSX syntax in the code - there's not really any cost to us resolving the config even if jsx == false.

In fact it's better if we do that because in a lot of cases we actually ignore the jsx setting!

So let's go with the second solution of just removing the parserOptions.jsx check entirely.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working good first issue Good for newcomers package: parser Issues related to @typescript-eslint/parser
Projects
None yet
3 participants