A promise wrapped in new Promise
Code longer than it needs to be: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. lessloc catches it as simpler.
What makes a promise wrapped in new Promise a bad practice?
The standard that calls it a bad practice: Bluebird: the explicit-construction anti-pattern.
What does lessloc do about a promise wrapped in new Promise?
lessloc catches it as simpler.
simpler(tier 2): Brute-force code with a shorter idiom:== True, an if/else that returns the condition, an index loop that only readsxs[i],.filter(...).length > 0, a catch that only rethrows, a flag loop that isany(), a hand-built counter, an__init__that@dataclasswrites, a React Effect that only sets state. ruff and clippy add more.
Examples
Caught as simpler:
js
export function load(url) {
return new Promise((resolve, reject) => {
fetch(url).then(resolve).catch(reject);
});
}Written well:
js
export function load(url) {
return fetch(url);
}Related patterns
The other patterns in Code longer than it needs to be:
- Brute-force idioms: lessloc catches it as
simpler, built in for Python, JS/TS, Go, Rust, Java and C#. ruff (in every hook) and clippy (inci) go deeper. - Hand-built counters and flag loops: lessloc catches it as
simpler. - A catch that only rethrows: lessloc catches it as
simpler. - Annotating types the compiler infers: lessloc catches it as
simpler. - A React Effect that only sets state from other values: lessloc catches it as
simpler. - Functions with many parameters (8 or more): lessloc catches it as
long-params. - Deep nesting: lessloc catches it as
deep-nesting. - Long functions: lessloc catches it as
long-function. - If-chains on literal values: lessloc catches it as
if-chain. - A file that keeps growing: lessloc catches it as
swollen-file. - Reformatting lines the task did not change: lessloc gives every session a rule against it and catches it as
churn. - Net growth past a budget: lessloc catches it as
net-growth. - Golfed code: lessloc catches it as
cleveranddense-lines.

