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

@bradzacher bradzacher commented Sep 6, 2020

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.
@typescript-eslint
Copy link

@typescript-eslint typescript-eslint bot commented Sep 6, 2020

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 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
9 of 10 checks passed
9 of 10 checks passed
Typecheck
Details
Unit tests Unit tests
Details
Code style and lint Code style and lint
Details
Run integration tests on primary Node.js version
Details
Run unit tests on other Node.js versions (10.x)
Details
Run unit tests on other Node.js versions (14.x)
Details
Publish the latest code as a canary version
Details
codecov/patch Codecov Report
Details
Semantic Pull Request ready to be squashed
Details
codecov/project Codecov Report
Details
@bradzacher bradzacher deleted the jsx-scope-analysis branch Sep 6, 2020
phaux added a commit to phaux/typescript-eslint that referenced this pull request Sep 28, 2020
…slint#2498)

Fixes typescript-eslint#2455
And part of typescript-eslint#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 typescript-eslint#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.
@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.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

1 participant
You can’t perform that action at this time.