# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-with" = "off" # or "error"
```

{/* End of the generated section. */}

## Examples

Reported, in a CommonJS file:

{/* bad {"filename": "legacy.cjs"} */}
```js
with (point) {
  distance = Math.sqrt(x * x + y * y);
}
```

Not reported:

{/* good {"filename": "legacy.cjs"} */}
```js
const { x, y } = point;
distance = Math.sqrt(x * x + y * y);
```
