unicorn/prefer-path2d
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-path2d": "error",
},
},
];function draw() {
context.moveTo(220, 60);
context.arc(170, 60, 50, 0, 2 * Math.PI);
context.stroke();
}
function step() {
draw();
requestAnimationFrame(step);
}
requestAnimationFrame(step);const path = new Path2D();
path.moveTo(220, 60);
path.arc(170, 60, 50, 0, 2 * Math.PI);
function step() {
context.stroke(path);
requestAnimationFrame(step);
}
requestAnimationFrame(step);Examples from the ESLint documentation.
unicorn/prefer-path2d
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-path2d": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer the most specific Object iterable method.
Prefer Promise.resolve() and Promise.reject() over trivial new Promise() calls.
Prefer Object.defineProperties() over multiple Object.defineProperty() calls.
Prefer Promise.withResolvers() when extracting resolver functions from new Promise().
Prefer moving ternaries into the minimal varying part of an expression.
Prefer queueMicrotask() over process.nextTick(), setImmediate(), and setTimeout(…, 0).