diff --git a/crates/oxc_linter/src/rules/eslint/no_with.rs b/crates/oxc_linter/src/rules/eslint/no_with.rs index 90d8d548f2e35..50491fc977594 100644 --- a/crates/oxc_linter/src/rules/eslint/no_with.rs +++ b/crates/oxc_linter/src/rules/eslint/no_with.rs @@ -17,11 +17,17 @@ pub struct NoWith; declare_oxc_lint!( /// ### What it does /// - /// Disallow `with` statements + /// Disallow [`with`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with) statements. /// /// ### Why is this bad? /// - /// The with statement is potentially problematic because it adds members of an object to the current scope, making it impossible to tell what a variable inside the block actually refers to. + /// The with statement is potentially problematic because it adds members + /// of an object to the current scope, making it impossible to tell what a + /// variable inside the block actually refers to. + /// + /// It is generally considered a bad practice and is forbidden in strict mode. + /// + /// This rule is not necessary in TypeScript code if `alwaysStrict` is enabled. /// /// ### Examples /// @@ -48,7 +54,19 @@ impl Rule for NoWith { fn test() { use crate::tester::Tester; - let pass = vec!["foo.bar()"]; + let pass = vec![ + "foo.bar();", + "/* with keyword in block comment */ foo();", + "// with in line comment\nfoo();", + "var obj = { with: 1 }; obj.with;", + "obj.with = 1;", + "class C { with() {} } new C().with();", + "console.log('with in string');", + "console.log(`with in template`);", + "const o = {}; o['with'] = 2;", + "const p = { ['with']: 3 }; p.with;", + "const { with: w } = { with: 4 }; w;", + ]; let fail = vec!["with(foo) { bar() }"];