user762579
user762579

Reputation:

TSLint : variable name must be in camelcase or uppercase

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

Upvotes: 50

Views: 45810

Answers (3)

Shank
Shank

Reputation: 414

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/

Upvotes: 23

AissaDevLab
AissaDevLab

Reputation: 784

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"
  ]
}

Upvotes: 3

Leonardo Venoso
Leonardo Venoso

Reputation: 1222

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"
    ]
  },
  // ...
}

Upvotes: 86

Related Questions