-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
react/jsx-no-undef allowGlobals option #1013
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
Conversation
With the `allowGlobals` enabled, the global scope will be ignored when checking for defined components. Without this option enabled, global variables will not be allowed when checking for defined components.
tests/lib/rules/display-name.js
Outdated
}] | ||
}], | ||
globals: { | ||
Foo: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this necessary? i wouldn't expect the display-name
tests to enable jsx-no-undef
tests/lib/rules/jsx-no-undef.js
Outdated
@@ -56,6 +56,29 @@ ruleTester.run('jsx-no-undef', rule, { | |||
'}' | |||
].join('\n'), | |||
parserOptions: parserOptions | |||
}, { | |||
code: '/*eslint no-undef:1*/ var React; React.render(<Text />);', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly, why would the core undef
rule be enabled for jsx-no-undef
tests? Rule tests should start with zero rules enabled except for the rule under test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the tests that were already there. I removed it.
tests/lib/rules/jsx-no-undef.js
Outdated
'};' | ||
].join('\n'), | ||
errors: [{ | ||
message: '\'Text\' is not defined.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there an "errors" section in the "valid" section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy and paste. I must have missed that section when I blinked while scrolling.
Also, maybe the name of the option should be changed since it's not really just checking imports. It's checking the module scope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the option name, perhaps disallowGlobals
or something like that would be more accurate?
docs/rules/jsx-no-undef.md
Outdated
|
||
The following patterns are considered okay and do not cause warnings: | ||
|
||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this should be jsx
(here and elsewhere)
docs/rules/jsx-no-undef.md
Outdated
|
||
```js | ||
... | ||
"jsx-no-undef": [<enabled>, { "importedOnly": <boolean> }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: In #1071 we are adding react/
to lines like this. It would be nice to get that in here if we touch this again.
docs/rules/jsx-no-undef.md
Outdated
... | ||
``` | ||
|
||
### `importedOnly` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make this an option instead of having it be the default behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like it'd be a breaking change - an option now, flipping the default later, seems safer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. I'll open an issue for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a02db45
to
0ecd498
Compare
0ecd498
to
dc3a643
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR to switch the option to allowGlobals
, and default it to false
.
@ljharb go for it |
This should allow for the use case outlined in #922.
With the
disallowGlobals
option enabled, the global scope will be ignoredwhen checking for defined components. Without this option enabled,
Pascal case global variables will be allowed when checking for defined
components.