feat(linter/eslint-plugin-unicorn): implement fixer for prefer-dom-node-append (#4306)

This commit is contained in:
Jelle van der Waa 2024-07-18 03:44:23 +02:00 committed by GitHub
parent 9df7b5675f
commit ed49e169cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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