mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(linter/eslint-plugin-unicorn): implement fixer for prefer-dom-node-append (#4306)
This commit is contained in:
parent
9df7b5675f
commit
ed49e169cb
1 changed files with 17 additions and 2 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue