Repository: eslint/eslint
File: lib/rules/no-useless-assignment.js (JavaScript)

Code before:
                                !isIdentifierUsedBetweenAssignedAndEqualSign(otherAssignment, targetAssignment.identifier)
                            ));

                        if (!assignmentInSegment) {

                            /*
                             * Stores the next segment to explore.
                             * If `assignmentInSegment` exists,
                             * we are guarding it because we don't need to explore the next segment.
                             */
                            subsequentSegmentData.queueSegments.push(...nextSegment.nextSegments);
                        }

                        /** @type {SubsequentSegmentData} */
                        const result = {
                            segment: nextSegment,
                            assignment: assignmentInSegment
                        };

                        subsequentSegmentData.results.push(result);
                        yield result;
                    }
                }


                const readReferences = targetAssignment.variable.references.filter(reference => reference.isRead() && reference.identifier.type === "Identifier");

                if (!readReferences.length) {

                    /*
                     * It is not just an unnecessary assignment, but an unnecessary (unused) variable
                     * and thus should not be reported by this rule because it is reported by `no-unused-vars`.
                     */
                    return;
                }

                /**
                 * Other assignment on the current segment and after current assignment.
                 */
                const otherAssignmentAfterTargetAssignment = allAssignments
                    .find(assignment => {
                        if (
                            assignment === targetAssignment ||
                            assignment.segments.length && assignment.segments.every(segment => !targetAssignment.segments.includes(segment))
                        ) {
                            return false;
                        }
                        if (isIdentifierEvaluatedAfterAssignment(targetAssignment, assignment.identifier)) {
                            return true;
                        }
                        if (

Review comment (suggestion):
Would this work for example from https://github.com/eslint/eslint/issues/19160#issuecomment-2499928852? I think it would be better to just skip checking anything for a variable that has at least one non-identifier reference.

Code after:
                                !isIdentifierUsedBetweenAssignedAndEqualSign(otherAssignment, targetAssignment.identifier)
                            ));

                        if (!assignmentInSegment) {

                            /*
                             * Stores the next segment to explore.
                             * If `assignmentInSegment` exists,
                             * we are guarding it because we don't need to explore the next segment.
                             */
                            subsequentSegmentData.queueSegments.push(...nextSegment.nextSegments);
                        }

                        /** @type {SubsequentSegmentData} */
                        const result = {
                            segment: nextSegment,
                            assignment: assignmentInSegment
                        };

                        subsequentSegmentData.results.push(result);
                        yield result;
                    }
                }


                if (targetAssignment.variable.references.some(ref => ref.identifier.type !== "Identifier")) {

                    /**
                     * Skip checking for a variable that has at least one non-identifier reference.
                     * It's generated by plugins and cannot be handled reliably in the core rule.
                     */
                    return;
                }

                const readReferences = targetAssignment.variable.references.filter(reference => reference.isRead());

                if (!readReferences.length) {

                    /*
                     * It is not just an unnecessary assignment, but an unnecessary (unused) variable
                     * and thus should not be reported by this rule because it is reported by `no-unused-vars`.
                     */
                    return;
                }

                /**
                 * Other assignment on the current segment and after current assignment.
                 */
                const otherAssignmentAfterTargetAssignment = allAssignments
                    .find(assignment => {
                        if (