简体   繁体   English

使用自定义tslint规则导致找不到实现

[英]Using custom tslint rule results in no implementation found

I'm having difficulty to understand why my custom typescript rule is not working. 我很难理解为什么我的自定义打字稿规则不起作用。 Below some code to show my setup. 下面的一些代码显示了我的设置。

package.json: 的package.json:

 {
  "name": "lintingrules",
  "version": "0.0.1",
  "description": "Custom linting rules",
  "main": "lintrules.json"
 }

lintrules.json: lintrules.json:

{
    "rulesDirectory": "./rules",
    "rules": {
        "enounderscore": true
    }
}

tslint.json of the project I want to use the linting rules: 我要使用linting规则的项目的tslint.json:

{
  "extends": ["lintingrules"]
}

In my folder src/rules I have one rule that uses tsquery . 在我的文件夹src/rules我有一个使用tsquery规则。 When using this in my angular project I always get the following message when running ng lint : 在我的角度项目中使用此命令时,运行ng lint时始终会收到以下消息:

Could not find implementations for the following rules specified in the configuration: enounderscore Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed. 找不到配置中指定的以下规则的实现:enounderscore尝试升级TSLint和/或确保已安装所有必需的自定义规则。 If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up. 如果TSLint是最近升级的,则可能已配置了旧规则,需要清除这些旧规则。

So my mistake was that I didn't use the convention that TSLint needs but just created a file with a random name: 所以我的错误是我没有使用TSLint所需的约定,而是创建了一个具有随机名称的文件:

Important conventions: 重要约定:

Rule identifiers are always kebab-cased. 规则标识符始终使用kebab大小写。 Rule files are always camel-cased (camelCasedRule.ts). 规则文件始终使用驼峰式(camelCasedRule.ts)。 Rule files must contain the suffix Rule. 规则文件必须包含后缀Rule。 The exported class must always be named Rule and extend from Lint.Rules.AbstractRule. 导出的类必须始终命名为Rule并从Lint.Rules.AbstractRule扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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