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

Allow PascalCase to React Component in @typescript-eslint/naming-convention rule #48

Closed
younho9 opened this issue Dec 7, 2021 · 3 comments · Fixed by #50
Closed

Allow PascalCase to React Component in @typescript-eslint/naming-convention rule #48

younho9 opened this issue Dec 7, 2021 · 3 comments · Fixed by #50
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@younho9
Copy link
Contributor

younho9 commented Dec 7, 2021

Currently @typescript-eslint/naming-convention rule reports "react function component is not strictCamelCase."

How about add overrides for .tsx (react file extension) ?

Maybe can override it in the following way or copy all configuration for @typescript-eslint/naming-convention

overrides: [
  {
    files: ['**/*.tsx'],
    rules: {
      // ...
      '@typescript-eslint/naming-convention': [
        'error',
        {
          selector: 'function',
          format: ['PascalCase', 'camelCase'],
        },
      ],
    },
  },
]
@fregante
Copy link
Member

I don't know how common this is in react, but react-table also uses object properties to specify components, so they're in PascalCase

https://react-table.tanstack.com/docs/quick-start#define-columns

So I had to append this to the config:

{
  selector: ["function", "objectLiteralProperty", "objectLiteralMethod"],
  format: ["PascalCase", "camelCase"]
}

@younho9
Copy link
Contributor Author

younho9 commented Dec 23, 2021

I found variable name could be PascalCase when declare component as arrow function.

This is enforced in the xo-react rule.

{
	selector: ['variable', 'function', 'objectLiteralProperty', 'objectLiteralMethod'],
	types: ['function'],
	format: ['StrictPascalCase', 'strictCamelCase'],
},

In order to select more specifically, it seems necessary to add function type.

@sindresorhus
Copy link
Member

PR welcome

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants