简体   繁体   中英

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

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

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/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM