Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

822
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda