Cristian Flórez
Cristian Flórez

Reputation: 2781

@typescript-eslint/naming-convention: How to allow PascalCase in const that only have arrow function expression?

Sometimes in const I store some arrow functions that returns React component:

export const HomeOutline = (style: ImageStyle): IconElement => (
  <Icon {...style} name="home-outline" pack="material" />
);

This is only allowed in this case, otherwise, I use the camelCase and UPPER_CASE naming convention in my variables. There is a way to catch const that store arrow functions?

Upvotes: 1

Views: 3001

Answers (2)

Mina
Mina

Reputation: 154

I was looking for something similar to your question, but for decorators.

I did it like this

'@typescript-eslint/naming-convention': [
    'warn',
    {
        selector: 'default',
        format: ['camelCase'],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
    },
    {
        selector: 'variable',
        format: ['camelCase', 'UPPER_CASE'],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
    },
    {
        selector: 'variable',
        modifiers: ['const', 'exported'],
        types: ['function'],
        format: ['PascalCase'],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
    },
    {
        selector: 'typeLike',
        format: ['PascalCase'],
    },
],

Upvotes: 3

Mohammad Reza Mrg
Mohammad Reza Mrg

Reputation: 2033

Look at this answer: https://stackoverflow.com/a/69244737/4751073

try to use selector as type or variable

Upvotes: 1

Related Questions