Skip to content

react/display-name: checkContextObjects misses context when TypeScript interface shares the same name #19607

@RomaLetodiani

Description

@RomaLetodiani

Summary

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

Reproduction

Detected (different names):

import { createContext } from "react";

interface PostHogGroupContextValue {
  value: string;
}

const PostHogGroupContext = createContext<PostHogGroupContextValue | null>(null);
// ^ eslint-plugin-react(display-name): Context definition is missing display name. ✅

Not detected (same name):

import { createContext } from "react";

interface PostHogGroupContext {
  value: string;
}

const PostHogGroupContext = createContext<PostHogGroupContext | null>(null);
// ^ No error reported ❌

Expected behavior

The rule should report a missing displayName regardless of whether a same-named TypeScript interface/type exists. TypeScript interfaces exist in the type namespace and have no relation to React's runtime displayName property.

Config

{
  "plugins": ["react"],
  "rules": {
    "react/display-name": ["error", { "checkContextObjects": true }]
  }
}

Environment

  • oxlint v1.47.0
  • macOS

Metadata

Metadata

Assignees

Labels

A-linterArea - LinterC-bugCategory - Bug

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions