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 isSuggestable = node.arguments[0].type !== "SequenceExpression";
                    const suggestedFixes = [];

                    if (isSuggestable) {
                        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
                    });
                }
            }
        }

        const listeners = {
            BinaryExpression: checkBinaryExpression

Review comment (suggestion):
```suggestion
                        const shouldWrap = callee.computed;
```

Property can also be a template literal, for example::

```js
var firstIndex = myArray[`indexOf`](NaN);
```

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
                    });
                }
            }
        }

        const listeners = {
            BinaryExpression: checkBinaryExpression