Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

830
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!