I'd like to enforce PascalCase for variables of type JSX.Element in my React+Typescript project. I frequently use the following pattern to create functional components, and I like to distinguish my eponymous export by giving it a PascalCase name:
//MyComponent.tsx
//PascalCase for MyComponent
export const MyComponent= (): JSX.Element =>{
return (
<div>
My Component
</div>
)
}
export default MyComponent
With my current linter settings, I get a warning that Variable name `MyComponent` must match one of the following formats: camelCase, UPPER_CASE. How can I add a rule to my linter settings that will enforce PascalCase for variables of type JSX.Element?
Here's my current .eslintrc.json:
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "react-hooks"],
"extends": [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "off",
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/explicit-function-return-type": [
"warn",
{
"allowExpressions": true
}
]
},
"settings": {
"react": {
"pragma": "React",
"version": "detect"
}
}
}