withStatements
Reports using with statements
✅ This rule is included in the ts untyped preset.
with statements are deprecated, unreliable, and difficult to reason about.
They are problematic because they add members of an object to the current scope, making it impossible to reliably know what a variable inside the block actually refers to.
If an object doesn’t have an expected variable, you’ll end up modifying a global instead of the expected property.
Examples
Section titled “Examples”with (container.property) { value = true;}let property = container.property;property.value = true;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase relies on non-standard behavior that involves with statements (which is highly discouraged), you might choose to disable this rule. For example, if you target a legacy runtime with non-standard JavaScript semantics, standard practices may not apply to you.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noWith - Deno:
no-with - ESLint:
no-with - Oxlint:
eslint/no-with
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.