50

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

  • 1
    Looks right to me at a glance, what version of TSLint are you using? – JKillian Mar 29 '17 at 17:32
  • I am using currently version 4.5.1. –  Mar 29 '17 at 20:57
  • Can you verify that TSLint is indeed using that config file? See if other changes to it affect things? – JKillian Mar 30 '17 at 02:22
  • You right ... using tslint --project '.' --config ./tslint.json it works now ... I don't understand why tslint was not using it when not specified... ( maybe weird behaviour w Webstorm IDE.. I'm using it..) –  Mar 30 '17 at 06:58

3 Answers3

85

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"
    ]
  },
  // ...
}
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
Leonardo Venoso
  • 1,203
  • 12
  • 15
23

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/

Shank
  • 413
  • 4
  • 15
  • When answering an old question, your answer would be much more useful to other StackOverflow users if you included some context to explain how your answer helps. See: [How do I write a good answer](https://stackoverflow.com/help/how-to-answer). – David Buck Jan 21 '20 at 12:44
3

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"
  ]
}
AissaDevLab
  • 584
  • 5
  • 9