Skip to content

Commit

Permalink
feat(linter/eslint-plugin-unicorn): implement fixer for prefer-dom-no…
Browse files Browse the repository at this point in the history
…de-append (#4306)
  • Loading branch information
jelly authored Jul 18, 2024
1 parent 9df7b56 commit ed49e16
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
});
}
}

Expand Down Expand Up @@ -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();
}

0 comments on commit ed49e16

Please sign in to comment.