Skip to content

Bug: eslint-plugin-react-hooks@5.0.0 only detects english component names #31446

Open
@DavidZidar

Description

@DavidZidar

React version: eslint-plugin-react-hooks@5.0.0

Steps To Reproduce

  1. Create a functional component with a name such as ÄndraVärde that starts with a non english upper case letter
  2. Run the linter

The current behavior

Sample error:

23:20 error React Hook "useSelectedState" is called in function "ÄndraVärde" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use" react-hooks/rules-of-hooks

The expected behavior

The linting should allow non english component names, React does.

The problem

Version 5.0.0 included the changes made in #25162 which modified the following method:

/**
* Checks if the node is a React component name. React component names must
* always start with an uppercase letter.
*/
function isComponentName(node) {
return node.type === 'Identifier' && /^[A-Z]/.test(node.name);
}

This code only allows english upper case letters A-Z which is not enough.

Proposed solution

Use .toUpperCase() and compare the result:

function isComponentName(node) { 
  return node.type === 'Identifier' && node.name[0] == node.name[0].toUpperCase(); 
} 

This should work with a lot more languages at least.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions