Skip to content

Bug: no-extra-boolean-cast fires on a shadowed Boolean, and --fix rewrites the code #21009

Description

@navi2-dil

Environment

Node version: v24.15.0
npm version: v11.12.1
Local ESLint version: v10.4.1
Global ESLint version: Not found
Operating System: win32 10.0.26200

What parser are you using?

Default (Espree)

What did you do?

Configuration
export default [
    { rules: { "no-extra-boolean-cast": "error" } }
];
function validate(Boolean) {
    if (Boolean(input)) {
        process(input);
    }
}

Boolean here is the function parameter, not the global. So Boolean(input) is a call to whatever was passed in, not a redundant cast.

What did you expect to happen?

No error. The Boolean in Boolean(input) resolves to the parameter, so there's nothing redundant about it.

What actually happened?

2:9  error  Redundant Boolean call  no-extra-boolean-cast

And --fix rewrites it:

 function validate(Boolean) {
-    if (Boolean(input)) {
+    if (input) {
         process(input);
     }
 }

The call to the parameter is just deleted. Anyone running --fix on save or in CI gets this applied automatically, so the behavior change slips through silently.

Same thing happens with the other ways of shadowing Boolean:

// let binding
let Boolean = v => v != null && v !== "";
while (Boolean(value)) { value = next(); }
// --fix -> while (value) { value = next(); }

// class
class Boolean { static from(v) { return !!v; } }
if (Boolean(x)) { doSomething(); }
// --fix -> if (x) { doSomething(); }

Shadowing Boolean is admittedly an unusual thing to do, but it's valid code and rewriting it is still wrong

Link to Minimal Reproducible Example

https://eslint.org/play/#eyJ0ZXh0IjoiZnVuY3Rpb24gdmFsaWRhdGUoQm9vbGVhbikge1xuICAgIGlmIChCb29sZWFuKGlucHV0KSkge1xuICAgICAgICBwcm9jZXNzKGlucHV0KTtcbiAgICB9XG59Iiwib3B0aW9ucyI6eyJydWxlcyI6eyJuby1leHRyYS1ib29sZWFuLWNhc3QiOlsiZXJyb3IiXX0sImxhbmd1YWdlT3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFGZWF0dXJlcyI6e319fX19

Participation

  • I am willing to submit a pull request for this issue.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

Additional comments

No response

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionbugESLint is working incorrectlyrepro:yesIssues with a reproducible exampleruleRelates to ESLint's core rules

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions