diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs b/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs index 18382d3a63348..039b7ebd6a9c2 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs @@ -319,6 +319,12 @@ fn test() { (r"(el as HTMLElement).onmouseenter = onAnchorMouseEnter;", None), ]; + // TODO: Implement autofix and use these tests. + // let _fix = vec![( + // "(el as HTMLElement).onmouseenter = onAnchorMouseEnter;", + // "(el as HTMLElement).addEventListener('mouseenter', onAnchorMouseEnter);", + // )]; + Tester::new(PreferAddEventListener::NAME, PreferAddEventListener::PLUGIN, pass, fail) .test_and_snapshot(); } diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_array_find.rs b/crates/oxc_linter/src/rules/unicorn/prefer_array_find.rs index 61c235c79aced..61a8e37db06ed 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_array_find.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_array_find.rs @@ -605,6 +605,7 @@ fn test() { "array.filter(foo)?.pop()", ]; + // TODO: Implement autofix and use these tests. let _fix: Vec<(&'static str, &'static str, Option)> = vec![ ("array.filter(foo)[0]", "array.find(foo)", None), ("array.filter(foo, thisArgument)[0]", "array.find(foo, thisArgument)", None), diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs b/crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs index ea03904d9fa09..ec666b05e3ea7 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs @@ -614,6 +614,7 @@ fn test() { }", ]; + // TODO: Implement autofix and use these tests. let _fix = vec![ ( r"function abc(foo) { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs b/crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs index ca2f2b78ee561..0fd17c1b0a51e 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_logical_operator_over_ternary.rs @@ -132,6 +132,10 @@ fn test() { "await a ? (await (a)) : (foo)", "(await a) ? await (a) : (foo)", "(await a) ? (await (a)) : (foo)", + "const foo = []; + !+a ? b : +a", + "const foo = []; + a && b ? a && b : 1", ]; Tester::new( diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs b/crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs index 5e238ab64f06e..cb1de98e1cc35 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_modern_dom_apis.rs @@ -207,6 +207,83 @@ fn test() { ), ]; + // TODO: Implement autofix and use these tests. + let _fix = vec![ + ( + "parentNode.replaceChild(newChildNode, oldChildNode);", + "oldChildNode.replaceWith(newChildNode);", + ), + ("parentNode.insertBefore(newNode, referenceNode);", "referenceNode.before(newNode);"), + ( + r#"referenceNode.insertAdjacentText("beforebegin", "text");"#, + r#"referenceNode.before("text");"#, + ), + ( + r#"referenceNode.insertAdjacentText("afterbegin", "text");"#, + r#"referenceNode.prepend("text");"#, + ), + ( + r#"referenceNode.insertAdjacentText("beforeend", "text");"#, + r#"referenceNode.append("text");"#, + ), + ( + r#"referenceNode.insertAdjacentText("afterend", "text");"#, + r#"referenceNode.after("text");"#, + ), + ( + r#"const foo = referenceNode.insertAdjacentText("beforebegin", "text");"#, + r#"const foo = referenceNode.before("text");"#, + ), + ( + r#"foo = referenceNode.insertAdjacentText("beforebegin", "text");"#, + r#"foo = referenceNode.before("text");"#, + ), + ( + r#"referenceNode.insertAdjacentElement("beforebegin", newNode);"#, + "referenceNode.before(newNode);", + ), + ( + r#"referenceNode.insertAdjacentElement("afterbegin", "text");"#, + r#"referenceNode.prepend("text");"#, + ), + ( + r#"referenceNode.insertAdjacentElement("beforeend", "text");"#, + r#"referenceNode.append("text");"#, + ), + ( + r#"referenceNode.insertAdjacentElement("afterend", newNode);"#, + "referenceNode.after(newNode);", + ), + ( + "parentNode.replaceChild( + newChildNode, + oldChildNode + );", + "oldChildNode.replaceWith(newChildNode);", + ), + ( + "parentNode. replaceChild( // inline comments + newChildNode, // inline comments + oldChildNode // inline comments + );", + "oldChildNode.replaceWith(newChildNode);", + ), + ( + r#"referenceNode.insertAdjacentElement( + "afterend", + newNode + );"#, + "referenceNode.after(newNode);", + ), + ( + r#"referenceNode.insertAdjacentElement( // inline comments + "afterend", // inline comments + newNode // inline comments + ); // inline comments"#, + "referenceNode.after(newNode); // inline comments", + ), + ]; + Tester::new(PreferModernDomApis::NAME, PreferModernDomApis::PLUGIN, pass, fail) .test_and_snapshot(); } diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_modern_math_apis.rs b/crates/oxc_linter/src/rules/unicorn/prefer_modern_math_apis.rs index 810e208f58ad6..a3a7387bc9db7 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_modern_math_apis.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_modern_math_apis.rs @@ -409,6 +409,8 @@ fn test() { ); } ", + // TODO: Fix this + // "Math.sqrt((( a ** 2 )) + (( b ** 2 + c ** 2 )) + (( d )) * (( d )) + (( e )) ** (( 2 )))", ]; Tester::new(PreferModernMathApis::NAME, PreferModernMathApis::PLUGIN, pass, fail) diff --git a/crates/oxc_linter/src/snapshots/unicorn_prefer_logical_operator_over_ternary.snap b/crates/oxc_linter/src/snapshots/unicorn_prefer_logical_operator_over_ternary.snap index 5457ac71f6691..f58c0e5b49340 100644 --- a/crates/oxc_linter/src/snapshots/unicorn_prefer_logical_operator_over_ternary.snap +++ b/crates/oxc_linter/src/snapshots/unicorn_prefer_logical_operator_over_ternary.snap @@ -126,3 +126,19 @@ source: crates/oxc_linter/src/tester.rs · ─────────────────────────────── ╰──── help: Switch to "||" or "??" operator + + ⚠ eslint-plugin-unicorn(prefer-logical-operator-over-ternary): Prefer using a logical operator over a ternary. + ╭─[prefer_logical_operator_over_ternary.tsx:2:10] + 1 │ const foo = []; + 2 │ !+a ? b : +a + · ──────────── + ╰──── + help: Switch to "||" or "??" operator + + ⚠ eslint-plugin-unicorn(prefer-logical-operator-over-ternary): Prefer using a logical operator over a ternary. + ╭─[prefer_logical_operator_over_ternary.tsx:2:10] + 1 │ const foo = []; + 2 │ a && b ? a && b : 1 + · ─────────────────── + ╰──── + help: Switch to "||" or "??" operator