Lint Rules

noStringCaseMismatch (since v11.0.0)

Disallow comparison of expressions modifying the string case with non-compliant value.

Examples

Invalid

if (s.toUpperCase() === "Abc") {}
nursery/noStringCaseMismatch.js:1:5 lint/nursery/noStringCaseMismatch  FIXABLE  ━━━━━━━━━━━━━━━━━━━━

   This expression always returns false.
  
  > 1 │ if (s.toUpperCase() === "Abc") {}
       ^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   This call convert the string to upper case
  
  > 1 │ if (s.toUpperCase() === "Abc") {}
       ^^^^^^^^^^^^^^^
    2 │ 
  
   ... but this value is not in upper case
  
  > 1 │ if (s.toUpperCase() === "Abc") {}
                           ^^^^^
    2 │ 
  
   Suggested fix: Use upper case string value.
  
    1  - if·(s.toUpperCase()·===·"Abc")·{}
      1+ if·(s.toUpperCase()·===·"ABC")·{}
    2 2  
  
while (s.toLowerCase() === "Abc") {}
nursery/noStringCaseMismatch.js:1:8 lint/nursery/noStringCaseMismatch  FIXABLE  ━━━━━━━━━━━━━━━━━━━━

   This expression always returns false.
  
  > 1 │ while (s.toLowerCase() === "Abc") {}
          ^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   This call convert the string to lower case
  
  > 1 │ while (s.toLowerCase() === "Abc") {}
          ^^^^^^^^^^^^^^^
    2 │ 
  
   ... but this value is not in lower case
  
  > 1 │ while (s.toLowerCase() === "Abc") {}
                              ^^^^^
    2 │ 
  
   Suggested fix: Use lower case string value.
  
    1  - while·(s.toLowerCase()·===·"Abc")·{}
      1+ while·(s.toLowerCase()·===·"abc")·{}
    2 2  
  

Valid

if (s.toUpperCase() === "ABC") {}
while (s.toLowerCase() === "abc") {}
for (;s.toLocaleLowerCase() === "ABC";) {}
while (s.toLocaleUpperCase() === "abc") {}
for (let s = "abc"; s === "abc"; s = s.toUpperCase()) {}