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

feat(scope-manager): add support for JSX scope analysis #2498

Merged
merged 1 commit into from Sep 6, 2020

Conversation

bradzacher
Copy link
Member

Fixes #2455
And some of #2477

JSX is a first-class citizen of TS, so we should really support it as well.

I was going to just rely upon eslint-plugin-react's patch lint rules (react/jsx-uses-react and react/jsx-uses-vars), but that leaves gaps in our tooling.
For example #2455, consistent-type-imports makes assumptions and can create invalid fixes for react without this change.
We could add options to that lint rule for the factory, but that is kind-of a sub-par experience and future rule authors will likely run into similar problems that they'd have to manually build support for.

  • Adds full scope analysis support for JSX.
  • Adds two new parserOption:
    • jsxPragma - the name to use for constructing JSX elements. Defaults to "React". Will be auto detected from the tsconfig.
    • jsxFragmentName - the name that unnamed JSX fragments use. Defaults to null (i.e. assumes React.Fragment). Will be auto detected from the tsconfig.

Fixes #2455
And part of #2477

JSX is a first-class citizen of TS, so we should really support it as well.
I was going to just rely upon `eslint-plugin-react`'s patch lint rules (`react/jsx-uses-react` and `react/jsx-uses-vars`), but that leaves gaps in our tooling.
For example #2455, `consistent-type-imports` makes assumptions and can create invalid fixes for react without this change.
We could add options to that lint rule for the factory, but that is kind-of a sub-par experience and future rule authors will likely run into similar problems.

- Adds full scope analysis support for JSX.
- Adds two new `parserOption`:
    - `jsxPragma` - the name to use for constructing JSX elements. Defaults to `"React"`. Will be auto detected from the tsconfig.
    - `jsxFragmentName` - the name that unnamed JSX fragments use. Defaults to `null` (i.e. assumes `React.Fragment`). Will be auto detected from the tsconfig.
@bradzacher bradzacher added the enhancement New feature or request label Sep 6, 2020
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @bradzacher!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

codecov bot commented Sep 6, 2020

Codecov Report

Merging #2498 into master will decrease coverage by 0.01%.
The diff coverage is 86.84%.

@@            Coverage Diff             @@
##           master    #2498      +/-   ##
==========================================
- Coverage   92.82%   92.80%   -0.02%     
==========================================
  Files         290      290              
  Lines        9393     9429      +36     
  Branches     2631     2638       +7     
==========================================
+ Hits         8719     8751      +32     
- Misses        322      323       +1     
- Partials      352      355       +3     
Flag Coverage Δ
#unittest 92.80% <86.84%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/scope-manager/src/referencer/Reference.ts 90.00% <ø> (ø)
packages/scope-manager/src/scope/ScopeBase.ts 91.66% <ø> (ø)
packages/scope-manager/src/analyze.ts 72.41% <40.00%> (-4.51%) ⬇️
...ackages/scope-manager/src/referencer/Referencer.ts 93.93% <93.93%> (ø)

@bradzacher bradzacher merged commit f887ab5 into master Sep 6, 2020
@bradzacher bradzacher deleted the jsx-scope-analysis branch September 6, 2020 03:20
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[consistent-type-imports] Auto-fix not working well with ReactJS imports
1 participant