TSLint : variable name must be in camelcase or uppercase

TypescriptTslint

Typescript Problem Overview


I have some variable names starting with leading underscore , I still get this warning after updating my tslint.json

tslint.json

{
  "extends": "tslint:recommended",
  "rules": {
    "variable-name": [
      true,
      "ban-keywords",
      "check-format",
      "allow-leading-underscore"
    ]
  },
  "exclude": [
    "build/**/*",
    "node_modules/**/*",
    "tmp/**/*"
  ]
}

where am I wrong ?

thanks for feedback

UPDATE

I am using version 4.5.1 of TSLint

Typescript Solutions


Solution 1 - Typescript

You can solve the problem by editing your tslint.json and adding "allow-leading-underscore" to the "variable-name" array of your "rules".

// tslint.json contents
{
  // ...
  "rules": {
    // ...
    "variable-name": [
      true,
      // ...
      "allow-leading-underscore"
    ]
  },
  // ...
}

Solution 2 - Typescript

I have updated tslint.json, configured the file and added optional arguments to the array of variable-name.

>"allow-leading-underscore" allows underscores at the beginning (only has an effect if “check-format” specified) > > "allow-pascal-case" allows PascalCase in addition to lowerCamelCase. > > "allow-snake-case" allows snake_case in addition to lowerCamelCase. > >"allow-trailing-underscore" allows underscores at the end. (only has an effect if “check-format” specified)

{
  // ...
  "rules": {
    "variable-name": [
      true,
      "allow-leading-underscore"
    ],
  },
  // ...
}

You can configure tslint.json according to your requirements.

This link might be helpful. https://palantir.github.io/tslint/rules/variable-name/

Solution 3 - Typescript

You can solve the problem by editing your tslint.json and adding all this properties to the "variable-name" :

"variable-name": {
  "options": [
    "ban-keywords",
    "check-format",
    "allow-pascal-case",
    "allow-leading-underscore",
    "allow-snake-case",
    "allow-trailing-underscore",
    "require-const-for-all-caps"
  ]
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser762579View Question on Stackoverflow
Solution 1 - TypescriptLeonardo VenosoView Answer on Stackoverflow
Solution 2 - TypescriptShankView Answer on Stackoverflow
Solution 3 - TypescriptAissaDevLabView Answer on Stackoverflow