eslint: [bug] undefined variable `name` does not trigger errors or warnings in JSX.
I’m not sure which rule is failing, but if I had a component which had prop name and used it in JSX, while refactoring and renaming prop to title
, the leftovers of name prop iN JSX slept unnoticed, and caused errors in production, even with typescript.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (10 by maintainers)
There is a
no-restricted-globals
rule for that. create-react-app is maintaining aconfusing-browser-globals
package, which is a list of globals you usually want to restrict, includingname
andevent
.You can set
env: { browser: false }
(instead oftrue
) in your config and use/* globals ...*/
comments to enable only browser globals you want to use in that file.Or, as @webOS101 recommended in this comment, enable just
window
/document
and access browser globals only through those, in which case you should also setenv: { browser: false }
.Either of these solutions would lead to no-undef rule warnings on the
name
reference.A problem with this might be if
@typescript-eslint/eslint-recommended
config turnsno-undef
off, in which case the solution withno-restricted-globals
as recommended by @ark120202 in this comment looks like the best approach for a typescript project.I think the solution to your problem is to remove ‘browser’ from your environment. Then, you won’t be able to access browser globals implicitly like that.
That’s a good solution, too. There is also this link I found: https://github.com/microsoft/TypeScript/issues/14306#issuecomment-552890299
Explicitly enable the globals you need (
window
ordocument
, for example) and only access the browser through those globals. I can’t speak to the typescript side of things as I just don’t know enough about configuring that.Using version numbers like
latest
is not very informative, particularly for people looking at this issue in the future. New releases of components happen daily so ‘latest’ at 12:00 may not be the same as ‘latest’ at 2:00.