noWith (since v12.0.0)
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.
Examples
Invalid
function f() {
with (point) {
r = Math.sqrt(x * x + y * y); // is r a member of point?
}
}
nursery/noWith.js:2:3 lint/nursery/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.