Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions crates/oxc_linter/src/rules/eslint/no_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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() }"];

Expand Down
Loading