Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

no-with

Disallow with statements

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:

with (point) {
  distance = Math.sqrt(x * x + y * y);
}

Not reported:

const { x, y } = point;
distance = Math.sqrt(x * x + y * y);