-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Docs: Add note regarding PascalCase
function components in naming-convention rule
#7108
Comments
PascalCase
functional components in naming-convention rule
Yeah it's a major problem for static analysis of function components. You should see the crazy logic It's also a sticking point for various research exploration projects within the react team. For a react codebase I'd recommend specifying functions separately to specifically allow both But also some codebases use arrow functions for components... so you'd also need to allow both styles for variables as well! |
This is why I would suggest adding the caution note in that first example. I think React functional components are common enough (or will be sooner or later), that a caution admonition in the docs would help user that may be less knowledgeable in the inner working of all those terms. Maybe could be worded a bit differently. :::caution
Using this rule will trigger errors on functional components using `PascalCase` convention, as used in React. You may want to use `"format": ["camelCase", "PascalCase"]` to allow both convention.
See [issue #2607](https://github.com/typescript-eslint/typescript-eslint/issues/2607) for more information and [eslint-plugin-react/jsx-pascal-case rule](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md) rule.
:::
I am guilty of that! 🤣 However, I did limit the |
PascalCase
functional components in naming-convention rulePascalCase
function components in naming-convention rule
Accepting a PR to add an explicit note about UI library function components. A couple thoughts:
|
Before You File a Documentation Request Please Confirm You Have Done The Following...
Suggested Changes
Background
I was looking to use
naming-convention
for my React and non-React packages. It is known that React convention is to usePascalCase
component, while the rest iscamelCase
. Turns out, it is not possible to define a rule to cover this case, since there is nothing to distinguish a React component function from a non-component function (neither function arguments or return type are fool proof).It has been discussed in #2607 and #2692.
Requested change
Since the
PascalCase
pattern for component is quite common, I would like to see a note regarding this in the documentation of the naming convention rule. The best place could be in the first example, which shows how to enforce function tocamelCase
.Affected URL(s)
https://typescript-eslint.io/rules/naming-convention/
The text was updated successfully, but these errors were encountered: