-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Allow to configure implicitly required variables for JSX identifiers via pluggable API #1905
Comments
I wonder if it can be made even more generic so tools like Babel can also use such package (e.g. called |
Some notes in reply to babel/babel-eslint#6 (comment)
100% agreed that it's annoying that React makes us do this.
The main reason for wanting something more is that we don't want to make React an actual global variable. therefore using React's JSX syntax in a file without also requiring There's a few reasons for not wanting to put React on global, facebook/react#3252 is one example.
This would also be a sensible way to do it, but as it currently stands the compiler doesn't have knowledge of the module system so I don't think this is possible :( There is a proposal open that could mean Perhaps @sebmarkbage could weigh in? As for some sort of pluggable JSX extension module, I guess using the Plugin API would be doable? http://eslint.org/docs/developer-guide/working-with-plugins.html @gaearon |
An additional thing that makes this tricky is that we're not talking about exposing a declaration, we're talking about exposing a reference (or rather, inferring a reference). escope is used to track references to variables, and that's not exposed in plugins. It's technically possible to expose it, but then we'd need to figure out an interface that makes sense, and that's not very straightforward. Just so I'm being super clear: I'm completely open to creating something that allows the functionality you want. I just want it to be library-independent. And to be completely transparent: my fear is that such an effort would be quite large as opposed to finding a way outside of ESLint to do it. For instance, why not add the
Since you already need to run your code through a compilation step, adding something like this wouldn't interfere with developer workflow and would keep all concerns nicely separated. |
I understand your concerns above.
I like this option even less than adding “ignore” comments because it changes not just the code, but its semantics, and may cause subtle misunderstandings, bugs and maintenance cost. |
If it's hard to do and scope info is not currently exposed, I guess we'll have to stick with the comments. |
Interesting, your response actually makes me think that using a comment to opt out is the best way forward. If you have different usage patterns such that you can't just add the line automatically, that probably means you should be explicitly flagging this case. If you are importing I'm sorry, I wish there was an easy way to do this, but this is precisely why we allow fine-grained control of rules using those comments. I'd still encourage you to reach out to the React team to see if anything can be done. In the meantime, if anyone has any other ideas, please feel free to share. |
It seems so! One minor thing I don't like about it is linter won't warn me if I'm using JSX and not importing React—JSXHint did that for me. Still, I can live with that :-) Thank you for the discussion. Hopefully React team will solve this in the future. |
This is a perfect use case for a plugin - perhaps suggest this for yannickcr/eslint-plugin-react? |
Future versions will not require React to be in scope to use JSX. That is one consideration.
|
@sebmarkbage Thanks for the info, that totally makes sense based on this discussion. Since there's not anything left to do here, I'm closing the issue. Thanks for the conversation everyone. |
I was able to achieve the two goals using the existing rules extension behaviours, and have submitted them as PRs to https://github.com/yannickcr/eslint-plugin-react
These two checks should achieve the desired effect of changes suggested in this issue. |
I'm not a parser person so forgive if my terminology is off.
I propose #1867 not be ignored, but solved in a way that is not specific for React. To remind you, the original issue is React's JSX requiring
React
to be in scope:actually compiles to
I understand maintainers not wanting to special-case React in any way and I agree it's sensible. (Other libs may want to adopt JSX for their purposes.)
What I propose is making it possible (via custom parser like babel-eslint, or via some other extension point provided by ESLint) for consumer to specify which variables are implicitly required by JSX identifiers.
For example, I might have config like
Where
react-eslint
would be a package that, if specified, tells ESLint that any use of JSX identifier is equivalent to usingReact
in that scope.The text was updated successfully, but these errors were encountered: