I’m looking for an ESLint rule that disallows usage like location
and only allows window.location
. I’ve combed through the rules, but didn’t find one, does anyone know?
Advertisement
Answer
The no-restricted-globals rule will help you with this.
Add this to your .eslintrc
file
JavaScript
x
6
1
"no-restricted-globals" : [
2
"error",
3
"location",
4
"history",
5
]
6
So in the above example eslint won’t throw an error if you use window.location
or window.history
. You can add more window properties to the list.