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

[New] component detection: track React imports #3149

Merged
merged 2 commits into from Nov 29, 2021

Conversation

duncanbeevers
Copy link
Contributor

This PR adds a couple of basic tests to the existing Components.detect functionality.
Next it adds a facility for detecting the imported React identifiers during a parse, and adds a simple test for that detection.

This is an extraction of work initiated in #2921 and supports that PR

I think having a test runner for the Components.detect utility was worthwhile in itself, and separated that test-runner functionality into its own commit.

Test detection of Class Components and Stateless Function Components
Lay scaffolding for other flavors of tests including further component types, pragma detection, and utils functions
The default React import and named React import specifiers are tracked during a Components.detect rules definition.
Rules using Components.detect can access the default import specifier using `components.getDefaultReactImport()` and an array any named import specifiers using `components.getNamedReactImports()`
Within a rule, these specifier nodes can be checked to ensure identifiers in scope correspond with the imported identifiers.

Not treating this as semver-minor since it's not part of the documented API.
lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
tests/util/Component.js Outdated Show resolved Hide resolved
tests/util/Component.js Outdated Show resolved Hide resolved
tests/util/Component.js Outdated Show resolved Hide resolved
tests/util/Component.js Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the components-util-react-imports branch from dddf6c2 to 146eefb Compare November 28, 2021 23:26
@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2021

Codecov Report

Merging #3149 (a09debf) into master (32f2e24) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3149   +/-   ##
=======================================
  Coverage   97.50%   97.51%           
=======================================
  Files         119      119           
  Lines        8103     8129   +26     
  Branches     2888     2895    +7     
=======================================
+ Hits         7901     7927   +26     
  Misses        202      202           
Impacted Files Coverage Δ
lib/util/Components.js 98.94% <100.00%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32f2e24...a09debf. Read the comment docs.

@ljharb ljharb changed the title Components util react imports [New] component detection: track React imports Nov 28, 2021
@ljharb
Copy link
Member

ljharb commented Nov 28, 2021

Note: I'm not treating this as semver-minor, since it's not really part of the public API.

@ljharb ljharb force-pushed the components-util-react-imports branch from 146eefb to a09debf Compare November 29, 2021 03:49
@ljharb ljharb merged commit a09debf into jsx-eslint:master Nov 29, 2021
@duncanbeevers duncanbeevers deleted the components-util-react-imports branch March 15, 2022 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants