Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: [email protected] only detects english component names #31446

Open
DavidZidar opened this issue Nov 7, 2024 · 1 comment · May be fixed by #31456
Open

Bug: [email protected] only detects english component names #31446

DavidZidar opened this issue Nov 7, 2024 · 1 comment · May be fixed by #31456
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@DavidZidar
Copy link

React version: [email protected]

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.

@DavidZidar DavidZidar added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Nov 7, 2024
@garyguo123456789
Copy link

I would like to work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants