Skip to content

fix(linter): detect missing displayName when TS interface shares name with createContext (#19607)#19639

Closed
cobyfrombrooklyn-bot wants to merge 1 commit intooxc-project:mainfrom
cobyfrombrooklyn-bot:fix-issue-19607
Closed

fix(linter): detect missing displayName when TS interface shares name with createContext (#19607)#19639
cobyfrombrooklyn-bot wants to merge 1 commit intooxc-project:mainfrom
cobyfrombrooklyn-bot:fix-issue-19607

Conversation

@cobyfrombrooklyn-bot
Copy link

Problem

The react/display-name rule with checkContextObjects: true fails to detect a missing displayName when a TypeScript interface or type alias shares the same name as a createContext variable.

import { createContext } from 'react';

interface PostHogGroupContext { value: string; }
const PostHogGroupContext = createContext<PostHogGroupContext | null>(null);
// ^ Should report missing displayName, but doesn't

Root Cause

When interface Foo and const Foo = createContext() share the same name, oxc's semantic binder merges them into one symbol. The interface gets the primary symbol_declaration (since it's declared first). The is_react_component_node function receives the interface's AST node, finds no matching arm (it handles VariableDeclarator, FunctionDeclaration, etc. but not TSInterfaceDeclaration), and returns None. The code then falls through to check_context_assignment_references which checks write references, but a const initializer isn't a write reference.

Fix

When the primary declaration isn't a component, also check the symbol's redeclarations via ctx.scoping().symbol_redeclarations(). If a redeclaration (e.g. the VariableDeclarator with createContext()) is a component, it's detected correctly.

Tests

Added 3 test cases:

  1. Fail: Interface + createContext with same name (exact repro from react/display-name: checkContextObjects misses context when TypeScript interface shares the same name #19607)
  2. Fail: Type alias + createContext with same name
  3. Pass: Interface + createContext with same name but displayName is set

Updated snapshot. cargo test -p oxc_linter --lib -- display_name passes.

Tested locally on macOS ARM (Apple Silicon).

… with createContext variable

When a TypeScript interface/type alias has the same name as a variable
assigned to createContext(), the display-name rule failed to detect the
missing displayName. This happened because the interface gets the primary
symbol declaration, and is_react_component_node returns None for interface
nodes, falling through to context assignment reference checking which
also misses the const initializer.

The fix checks redeclarations when the primary declaration is not a
component. If the symbol has a redeclaration that is a component (e.g.
a VariableDeclarator with createContext()), it is detected correctly.

Fixes oxc-project#19607
@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Feb 23, 2026
@camc314 camc314 closed this Feb 23, 2026
@camc314
Copy link
Contributor

camc314 commented Feb 23, 2026

duplicate of #19608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants