Skip to content

react/display-name false negative when component body has function call with inline object as argument #3144

@berrtech

Description

@berrtech

Eslint and plugin versions:

"eslint": "7.32.0",
"eslint-plugin-react": "^7.27.0",

Relevant eslint configuration:

"react/display-name": "error",

Expected error:

Component definition is missing display name  react/display-name

As described in the title, the following code does not produce error:

const processData = (options?: { value: string }) =>
  options?.value || 'no data';

export const Component = observer(() => {
  const data = processData({ value: 'data' });
  return <Text>{data}</Text>;
});

If I remove { value: 'data' } argument, error is produced, as expected:

const processData = (options?: { value: string }) =>
  options?.value || 'no data';

export const Component = observer(() => {
  const data = processData();
  return <Text>{data}</Text>;
});

If I extract this argument to a separate variable error is produced too:

const processData = (options?: { value: string }) =>
  options?.value || 'no data';

export const Component = observer(() => {
  const options = { value: 'data' };
  const data = processData(options);
  return <Text>{data}</Text>;
});

That's weird, I don't think there is something wrong with configuration.
Repo reproducing error: https://github.com/berrtech/eslint-react-display-name

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions