no-with
Disallow with statements
warn by default
Inside with (object), a name such as x means object.x if the object has that property, and the variable x otherwise. You can't tell which one by reading the code, and adding a property to the object changes what the block does.
with is already a syntax error in strict mode, which includes every ES module and every class. The rule matters for CommonJS files and old scripts.
This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.
Configure#
On by default as a warning. To turn it off:
bunfig.toml
[lint.rules]
"no-with" = "off" # or "error"Examples#
Reported, in a CommonJS file:
legacy.cjs1 problem
withUnexpected use of with statement. (point) {
distance = Math.sqrt(x * x + y * y);
}legacy.cjsNo problems
const { x, y } = point;
distance = Math.sqrt(x * x + y * y);