Skip to content

noWith (since v1.0.0)

Diagnostic Category: lint/complexity/noWith

Sources:

Disallow with statements in non-strict contexts.

The with statement is potentially problematic because it adds members of an object to the current scope, making it impossible to tell what a variable inside the block actually refers to.

function f() {
with (point) {
r = Math.sqrt(x * x + y * y); // is r a member of point?
}
}
complexity/noWith.js:2:3 lint/complexity/noWith ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Unexpected use of with statement.
  
    1 │ function f() {
  > 2 │   with (point) {
     ^^^^^^^^^^^^^^
  > 3 │     r = Math.sqrt(x * x + y * y); // is r a member of point?
  > 4 │   }
     ^
    5 │ }
    6 │ 
  
   The with statement is potentially problematic because it adds members of an object to the current
    scope, making it impossible to tell what a variable inside the block actually refers to.