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

Created a no-named-import rule for React #2585

Open
wants to merge 8 commits into
base: master
from

Conversation

@el-angel
Copy link

el-angel commented Mar 3, 2020

No description provided.

el-angel added 2 commits Mar 3, 2020
@alexzherdev

This comment has been minimized.

Copy link
Contributor

alexzherdev commented Mar 3, 2020

Note that this can be achieved with the core no-restricted-syntax rule by using the following selector: "ImportDeclaration[source.value=\"react\"] :matches(ImportSpecifier, ImportNamespaceSpecifier)"

Copy link
Collaborator

ljharb left a comment

I think if we wanted to do this, it'd need to be able to support both patterns - forcing names, as well as disallowing them.

docs/rules/no-named-import.md Outdated Show resolved Hide resolved
@@ -0,0 +1,20 @@
# Prevent named imports from react (react/no-named-import)

Prevent the use of named imports from React, so it's visible in code that it's React and not custom code. This rule

This comment has been minimized.

Copy link
@ljharb

ljharb Mar 3, 2020

Collaborator

What about hooks, like useEffect etc?

This comment has been minimized.

Copy link
@el-angel

el-angel Mar 4, 2020

Author

I will add an options object which allows the developer to whitelist imports

This comment has been minimized.

Copy link
@el-angel

el-angel Mar 5, 2020

Author

I've added an option (forceImport, which could be true/false), where the linter will report when React.useState is used for example and should be imported. This way the rule can force certain imports which were used (React.useState) but not imported (import React from 'react').

@ljharb ljharb added the new rule label Mar 3, 2020
el-angel added 3 commits Mar 4, 2020
…cklist option for no-named-import and added more test cases to test those options.
README.md Outdated Show resolved Hide resolved
docs/rules/no-named-import.md Outdated Show resolved Hide resolved
el-angel added 3 commits Mar 5, 2020
…sion function to check whether React.{name} is used in code and report an error if needed
@el-angel

This comment has been minimized.

Copy link
Author

el-angel commented Mar 11, 2020

@ljharb Is there any feedback you have for me to get this PR approved? And do you have a clue on what goes wrong on Node V4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.