Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

831
Visualizações
Why eslint consider class as variable in naming-convention rule?

I using @typescript-eslint/naming-convention to enforce my variable names.

I set a rule that allow by default to every variable to be camelCase syntax, except class and object.

But when I use destructuring assignment with import function, I got eslint error that consider the BarClass as variable and apply the rule of camelCase instead of class rule:

Variable name BarClass must match one of the following formats: camelCase 12:11 - 12:19

Is there a way to fix that? How I make eslint to know that is a class and not variable?

typescript-eslint.io playground

class BarClass {

}

const geClass = async() => {
  return { BarClass };  
}

const bla = true;

(async () => {
  const { BarClass } = await geClass();

})();

eslint config:

{
  "rules": {
    "@typescript-eslint/naming-convention": [
      "error",
      {
        "selector": [
          "default"
        ],
        "format": [
          "camelCase"
        ]
      },
      {
        "selector": [
          "class", "objectLiteralProperty"
        ],
        "format": null
      }
    ]
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Well, a class is a TypeScript interface overlaying a JavaScript variable. See here

According to this there is no option for that rule to do what you want it to do

about 4 years ago · Juan Pablo Isaza Relatório

0

const { BarClass } = await geClass();

is the same thing as

const BarClass = (await geClass()).BarClass;

(it's easier to look at it this way). In this statement, the identifier BarClass appears two times: the first occurrence of BarClass is a variable name, the second one is a property name. ESLint is complaining that your variable is not in camel case, which is true. You could fix that by renaming the variable to match the rule conventions, but that would end up make your code less clear:

const { BarClass: barClass } = await geClass();

or equivalently

const barClass = (await geClass()).BarClass;

I'm afraid that the rule you are using has no way to make exceptions for variables with the type of a class, which would be the preferred solution.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda