typescript TSLint : 变量名必须是驼峰式或大写

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43099747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:39:36  来源:igfitidea点击:

TSLint : variable name must be in camelcase or uppercase

typescripttslint

提问by Leonardo Venoso

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

我有一些以下划线开头的变量名,更新我的 tslint.json 后我仍然收到这个警告

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

我使用的是 4.5.1 版的 TSLint

回答by Leonardo Venoso

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

您可以通过编辑您的tslint.json并将其添加"allow-leading-underscore""variable-name"您的"rules".

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

回答by Shank

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

我已经更新tslint.json、配置了文件并向变量名数组添加了可选参数。

"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)

"allow-leading-underscore"允许在开头使用下划线(仅在指定“check-format”时有效)

"allow-pascal-case"除了lowerCamelCase之外,还允许PascalCase。

"allow-snake-case"除了lowerCamelCase之外,还允许snake_case。

"allow-trailing-underscore"最后允许下划线。(仅在指定“check-format”时有效)

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

You can configure tslint.jsonaccording to your requirements.

您可以tslint.json根据您的要求进行配置。

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

此链接可能会有所帮助。https://palantir.github.io/tslint/rules/variable-name/