From ed49e169cb2d4d8de4826d5a1922c0fbd962d001 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Thu, 18 Jul 2024 03:44:23 +0200 Subject: [PATCH] feat(linter/eslint-plugin-unicorn): implement fixer for prefer-dom-node-append (#4306) --- .../rules/unicorn/prefer_dom_node_append.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs index 5c7cbf7df9e05..40f0b7fe6d62a 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs @@ -68,7 +68,9 @@ impl Rule for PreferDomNodeAppend { return; } - ctx.diagnostic(prefer_dom_node_append_diagnostic(span)); + ctx.diagnostic_with_fix(prefer_dom_node_append_diagnostic(span), |fixer| { + fixer.replace(span, "append") + }); } } @@ -111,5 +113,18 @@ fn test() { r"() => node?.appendChild(child)", ]; - Tester::new(PreferDomNodeAppend::NAME, pass, fail).test_and_snapshot(); + let fix = vec![ + ( + r"node.appendChild(child).appendChild(grandchild);", + r"node.append(child).append(grandchild);", + ), + (r"node?.appendChild(child);", r"node?.append(child);"), + ( + r"function foo() { return node.appendChild(child); }", + r"function foo() { return node.append(child); }", + ), + (r"const foo = [node.appendChild(child)]", r"const foo = [node.append(child)]"), + ]; + + Tester::new(PreferDomNodeAppend::NAME, pass, fail).expect_fix(fix).test_and_snapshot(); }