Repository: eslint/eslint
File: lib/rules/no-implicit-coercion.js (JavaScript)

Code before:
                ) {
                    return fixer.replaceText(node, ` ${recommendation}`);
                }

                return fixer.replaceText(node, recommendation);
            }

            context.report({
                node,
                messageId: "implicitCoercion",
                data: { recommendation },
                fix(fixer) {
                    if (!shouldFix) {
                        return null;
                    }

                    return fix(fixer);
                },
                suggest: [
                    {
                        messageId: "useRecommendation",
                        data: { recommendation },
                        fix(fixer) {
                            if (shouldFix) {
                                return null;
                            }

                            return fix(fixer);
                        }
                    }
                ]
            });
        }

        return {
            UnaryExpression(node) {
                let operatorAllowed;

                // !!foo
                operatorAllowed = options.allow.includes("!!");
                if (!operatorAllowed && options.boolean && isDoubleLogicalNegating(node)) {
                    const recommendation = `Boolean(${sourceCode.getText(node.argument.argument)})`;
                    const variable = astUtils.getVariableByName(sourceCode.getScope(node), "Boolean");
                    const booleanExists = Boolean(variable?.identifiers.length === 0);

                    report(node, recommendation, booleanExists);
                }

                // ~foo.indexOf(bar)
                operatorAllowed = options.allow.includes("~");
                if (!operatorAllowed && options.boolean && isBinaryNegatingOfIndexOf(node)) {

Review comment (suggestion):
[Question] Is it unusual to have a fixer or suggestion always `return null` based on some condition outside the fixing function? As in, would any downstream tooling be inconvenienced by falsely thinking these functions would do something?

Even if there's no functional difference, I did find it confusing to see a full `suggest` array. That feels slightly more unusual than the existing code's `if (!shouldFix)` condition being inside its `fix`. My _hunch_ is that it'd be better to conditionally assign `fix` and `suggest` only if they should exist.

```js
context.report({
   /* ... */
   ...(shouldFix ? { fix } : { suggest: [/* ... */] })
})
```

...but I'm new here and not confident in this suggestion.

Code after:
                ) {
                    return fixer.replaceText(node, ` ${recommendation}`);
                }

                return fixer.replaceText(node, recommendation);
            }

            context.report({
                node,
                messageId: "implicitCoercion",
                data: { recommendation },
                fix(fixer) {
                    if (!shouldFix) {
                        return null;
                    }

                    return fix(fixer);
                },
                suggest: [
                    {
                        messageId: "useRecommendation",
                        data: { recommendation },
                        fix(fixer) {
                            if (shouldFix || !shouldSuggest) {
                                return null;
                            }

                            return fix(fixer);
                        }
                    }
                ]
            });
        }

        return {
            UnaryExpression(node) {
                let operatorAllowed;

                // !!foo
                operatorAllowed = options.allow.includes("!!");
                if (!operatorAllowed && options.boolean && isDoubleLogicalNegating(node)) {
                    const recommendation = `Boolean(${sourceCode.getText(node.argument.argument)})`;
                    const variable = astUtils.getVariableByName(sourceCode.getScope(node), "Boolean");
                    const booleanExists = variable?.identifiers.length === 0;

                    report(node, recommendation, true, booleanExists);
                }

                // ~foo.indexOf(bar)
                operatorAllowed = options.allow.includes("~");
                if (!operatorAllowed && options.boolean && isBinaryNegatingOfIndexOf(node)) {