Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule proposal: no-useless-boolean-cast #2592

Open
geoffswift opened this issue Mar 8, 2025 · 0 comments
Open

Rule proposal: no-useless-boolean-cast #2592

geoffswift opened this issue Mar 8, 2025 · 0 comments

Comments

@geoffswift
Copy link

Description

We already have this good thing happening with prefer-native-coercion-functions

// ❌
const example = values.filter((value) => Boolean(value));

// ✅
const example = values.filter(Boolean);

Some times though you can have a situation where there's an unnecessary coercion though, when the callback is more complex.

The standard rule no-extra-boolean-cast stops me doing something like this

// ❌
if (Boolean(example))

// ✅
if (example)

Examples

// ❌
const example = records.filter(({ fieldname }) => Boolean(fieldname));

// ✅
const example = records.filter(({ fieldname }) => fieldname);
// ❌
const example = records.every((record) => Boolean(record.fieldname));

// ✅
const example = records.every((record) => record.fieldname);
// ❌
const example = records.some((record) => Boolean(record.fieldname));

// ✅
const example = records.some((record) => record.fieldname);

Proposed rule name

no-useless-boolean-cast

Additional Info

This might be giving some performance benefits.

@geoffswift geoffswift changed the title Rule proposal: Rule proposal: no-useless-boolean-cast Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant