feat(confusing-browser-globals): Add relevant messaging to no-restricted-globals eslint rule #10714
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BREAKING CHANGE: export from confusing-browser-globals package changed from String[] to Object[] - no change required if used in eslint no-restricted-globals config
I came across unclear messaging in eslint-config-airbnb today and traced it to this package, which is included in eslint-config-airbnb-base.
If you have code like:
Using this package in eslint no-restricted-globals rules will result in the error
Unexpected use of 'location'. no-restricted-globals
Which may communicate "don't use
location
at all" rather than the intended "preferwindow.location
or a local parameter to avoid unintended effects"So I've updated this package with clearer messaging, like in this case
Unexpected use of 'location'. Use local parameter or window.location instead no-restricted-globals
And in doing so realised we don't want to recommend using
window.<property>
everywhere, for example the following code:We'd catch this and suggest using the (missing) local value and not
window.event
.So I extended the list with a suggestion between
window
,document
,WorkerGlobalScope
*, ornone
to determine the correct messaging, and added tests covering each scenario.Since the output of this package changes, it would break anywhere that strictly expects an array of strings to be exported (i.e. not being used in eslint config). It should release as a breaking change and new major version.
*
WorkerGlobalScope
applies toself
included in this list, which made most sense to me but could be removed entirely from the list considering https://developer.mozilla.org/en-US/docs/Web/API/Window/self