-
-
Notifications
You must be signed in to change notification settings - Fork 417
prefer-global-this: Fix auto-fix for typeof window
#2501
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
typeof window and typeof selfprefer-global-this: ignore typeof window and typeof self
|
Are there any use cases that we have to use const isBrowser = 'window' in globalThis;
const isNode = 'process' in globalThis; |
|
I think it should emit an error, just not auto-fix. Or the check could auto-fix to |
|
Auto fix to Should we fix it to |
prefer-global-this: ignore typeof window and typeof selfprefer-global-this: fix auot-fix for typeof window
|
How is it not safe? |
Although This is in an unfixable case. - const type = typeof window;
+ const type = 'window' in globalThis;
switch (type) {
case 'undefined': {
console.log('Node.js');
break;
}
case 'object': {
console.log('Browser');
break;
}
default: {
// unknown
}
}I suggest the following solutions: Option 1. Option 2. Don't provide the fix Option 3. Detect the case |
|
Lets go with |
This is exactly what this PR does. @fisker Could you review it? |
prefer-global-this: fix auot-fix for typeof windowprefer-global-this: Fix auto-fix for typeof window
|
Using |
fix #2468