Skip to content

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.

with (container.property) {
value = true;
}

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.