unicorn/prefer-promise-try
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-promise-try": "error",
},
},
];new Promise(resolve => resolve(fn()));new Promise(resolve => resolve(fn(argument)));Promise.resolve().then(fn);Promise.try(() => fn());Promise.try(() => fn(argument));Promise.try(fn);Examples from the ESLint documentation.
unicorn/prefer-promise-try
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-promise-try": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer private class fields over the underscore-prefix convention.
Prefer RegExp#exec() over String#match() for non-global regular expressions.
Prefer an options object over optional positional parameters.
Prefer :scope when using element query selector methods.
Prefer observer APIs over resize and scroll listeners with layout reads.