salesforce / eslint-plugin-lwc

Official ESLint rules for LWC
MIT License
98 stars 32 forks source link

@W-17070457 Allow multi conditional !import.meta.env.SSR statements #171

Open a-chabot opened 1 week ago

a-chabot commented 1 week ago

@W-17070457 Allow multi conditional !import.meta.env.SSR statements

@lwc/lwc/ssr/no-unsupported-properties did not recognize when there is a multi conditional check with !import.meta.env.SSR.

Example: These is the scenario we are trying to fix:

if (!import.meta.env.SSR && randomOtherCheck) {
  this.dispatchEvent(someEvent);
} 

if (randomOtherCheck && !import.meta.env.SSR) {
  this.dispatchEvent(someEvent);
} 

if (!a && b && !c && d && !import.meta.env.SSR) {
  this.dispatchEvent(someEvent);
} 

let hello = (!import.meta.env.SSR && a) ? yes : no

if (!import.meta.env.SSR) {
  this.dispatchEvent(someEvent);
} 
nolanlawson commented 1 week ago

BTW one slightly broken thing I noticed is that isWindowOrDocumentCheck doesn't bother to check the right-hand-side:

https://github.com/salesforce/eslint-plugin-lwc/blob/c5d0cbbe19a6f0d56e4e0b92d29b592baf8c2988/lib/util/ssr.js#L54-L62

This means that it treats typeof document === 'undefined' the same as typeof document === 'object'. This doesn't need to be fixed in this PR, but it is odd since they mean completely different things.