-
-
Notifications
You must be signed in to change notification settings - Fork 428
Open
Labels
Description
Description
When writing multiple conditions, the simple one should come first.
I believe this can improve performance. The direct boolean check and variable ===/!== comparison are obviously cheaper.
Examples
// ❌
if (check(foo) && bar);
// ✅
if (bar && check(foo));// ❌
if (foo.bar.baz === 1 && bar === 2);
// ✅
if (bar === 2 && foo.bar.baz === 1);Proposed rule name
simple-condition-first
Additional Info
There is an internal rule in Prettier codebase checking a particular case https://github.com/prettier/prettier/blob/46061a160f7a6726d11d047647d59036435a3279/scripts/tools/eslint-plugin-prettier-internal-rules/test.js#L39-L44 , but it will be great to have a generic rule.
Reactions are currently unavailable