Repository: eslint/eslint
File: lib/rules/use-isnan.js (JavaScript)

Code before:
                }
            }
        }

        /**
         * Checks the given `CallExpression` node for `.indexOf(NaN)` and `.lastIndexOf(NaN)`.
         * @param {ASTNode} node The node to check.
         * @returns {void}
         */
        function checkCallExpression(node) {
            const callee = astUtils.skipChainExpression(node.callee);

            if (callee.type === "MemberExpression") {
                const methodName = astUtils.getStaticPropertyName(callee);

                if (
                    (methodName === "indexOf" || methodName === "lastIndexOf") &&
                    node.arguments.length === 1 &&
                    isNaNIdentifier(node.arguments[0])
                ) {

                    /*
                     * To retain side effects, it's essential to address `NaN` beforehand, which
                     * is not possible with fixes like `arr.findIndex(Number.isNaN)`.
                     */
                    const isFixable = node.arguments[0].type !== "SequenceExpression";
                    const suggestedFixes = [];

                    if (isFixable) {
                        const shouldWrap = callee.property.type === "Literal";
                        const findIndexMethod = methodName === "indexOf" ? "findIndex" : "findLastIndex";
                        const propertyName = shouldWrap ? `"${findIndexMethod}"` : findIndexMethod;

                        suggestedFixes.push({
                            messageId: "replaceWithFindIndex",
                            data: { methodName: findIndexMethod },
                            fix: fixer => [
                                fixer.replaceText(callee.property, propertyName),
                                fixer.replaceText(node.arguments[0], "Number.isNaN")
                            ]
                        });
                    }

                    context.report({
                        node,
                        messageId: "indexOfNaN",
                        data: { methodName },
                        suggest: suggestedFixes
                    });
                }
            }

Review comment (suggestion):
I think `isFixable` actually means `isSuggestable`? (To disambiguate between fixes and suggestions, it's probably better to keep the naming in line.)

Code after:
                }
            }
        }

        /**
         * Checks the given `CallExpression` node for `.indexOf(NaN)` and `.lastIndexOf(NaN)`.
         * @param {ASTNode} node The node to check.
         * @returns {void}
         */
        function checkCallExpression(node) {
            const callee = astUtils.skipChainExpression(node.callee);

            if (callee.type === "MemberExpression") {
                const methodName = astUtils.getStaticPropertyName(callee);

                if (
                    (methodName === "indexOf" || methodName === "lastIndexOf") &&
                    node.arguments.length === 1 &&
                    isNaNIdentifier(node.arguments[0])
                ) {

                    /*
                     * To retain side effects, it's essential to address `NaN` beforehand, which
                     * is not possible with fixes like `arr.findIndex(Number.isNaN)`.
                     */
                    const isSuggestable = node.arguments[0].type !== "SequenceExpression";
                    const suggestedFixes = [];

                    if (isSuggestable) {
                        const shouldWrap = callee.computed;
                        const findIndexMethod = methodName === "indexOf" ? "findIndex" : "findLastIndex";
                        const propertyName = shouldWrap ? `"${findIndexMethod}"` : findIndexMethod;

                        suggestedFixes.push({
                            messageId: "replaceWithFindIndex",
                            data: { methodName: findIndexMethod },
                            fix: fixer => [
                                fixer.replaceText(callee.property, propertyName),
                                fixer.replaceText(node.arguments[0], "Number.isNaN")
                            ]
                        });
                    }

                    context.report({
                        node,
                        messageId: "indexOfNaN",
                        data: { methodName },
                        suggest: suggestedFixes
                    });
                }
            }