更新 TSLint 错误:找不到配置中指定的以下规则的实现

Posted

技术标签:

【中文标题】更新 TSLint 错误:找不到配置中指定的以下规则的实现【英文标题】:Update TSLint Errors : Could not find implementations for the following rules specified in the configuration 【发布时间】:2017-04-16 22:01:12 【问题描述】:

我将我的 tslint 升级到 4.0.2,现在我收到很多类似以下的错误

Could not find implementations for the following rules specified in the configuration:
    directive-selector-name
    component-selector-name
    directive-selector-type
    component-selector-type
    directive-selector-prefix
    component-selector-prefix
    label-undefined
    no-constructor-vars
    no-duplicate-key
    no-unreachable
    use-strict

我认为问题可能是我的 tslint.json 可能已过时,我需要更新它,但我没有找到任何有关如何执行此操作的信息,或者即使我的假设是正确的。

tslint.json


  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": 
    "directive-selector-name": [true, "camelCase"],
    "component-selector-name": [true, "kebab-case"],
    "directive-selector-type": [true, "attribute"],
    "component-selector-type": [true, "element"],
    "directive-selector-prefix": [true, "my"],
    "component-selector-prefix": [true, "my"],
    "use-input-property-decorator": true,
    "use-output-property-decorator": true,
    "use-host-property-decorator": true,
    "no-attribute-parameter-decorator": true,
    "no-input-rename": true,
    "no-output-rename": true,
    "no-forward-ref" :true,
    "use-life-cycle-interface": true,
    "use-pipe-transform-interface": true,
    "pipe-naming": [true, "camelCase", "my"],
    "component-class-suffix": true,
    "directive-class-suffix": true,
    "ban": [true,
      ["_", "extend"],
      ["_", "isNull"],
      ["_", "isDefined"]
    ],
    "class-name": true,
    "comment-format": [false,
      "check-space",
      "check-lowercase"
    ],
    "curly": true,
    "eofline": true,
    "forin": true,
    "indent": [true, 2],
    "interface-name": true,
    "jsdoc-format": true,
    "label-position": true,
    "label-undefined": true,
    "max-line-length": [false, 140],
    "member-ordering": [true,
      "public-before-private",
      "static-before-instance",
      "variables-before-functions"
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-constructor-vars": false,
    "no-debugger": true,
    "no-duplicate-key": true,
    "no-duplicate-variable": true,
    "no-empty": true,
    "no-eval": true,
    "no-string-literal": true,
    "no-switch-case-fall-through": true,
    "trailing-comma": true,
    "no-trailing-whitespace": true,
    "no-unused-expression": true,
    "no-unused-variable": true,
    "no-unreachable": true,
    "no-use-before-declare": true,
    "no-var-requires": true,
    "one-line": [true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "quotemark": [true, "single"],
    "radix": true,
    "semicolon": true,
    "triple-equals": [true, "allow-null-check"],
    "typedef": [true,
      "callSignature",
      "indexSignature",
      "parameter",
      "propertySignature",
      "variableDeclarator"
    ],
    "typedef-whitespace": [true,
      ["callSignature", "noSpace"],
      ["catchClause", "noSpace"],
      ["indexSignature", "space"]
    ],
    "use-strict": false,
    "variable-name": false,
    "whitespace": [true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ]
  

packages.json


  "dependencies": 
    "@angular/common": "^2.2.4",
    "@angular/compiler": "^2.2.4",
    "@angular/core": "^2.2.4",
    "@angular/forms": "^2.2.4",
    "@angular/http": "^2.2.4",
    "@angular/platform-browser": "^2.2.4",
    "@angular/platform-browser-dynamic": "^2.2.4",
    "@angular/router": "^3.2.4",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.14",
    "ag-grid": "^7.0.0",
    "angularfire2": "^2.0.0-beta.5",
    "core-js": "^2.4.1",
    "firebase": "^3.6.2",
    "rxjs": "5.0.0-rc.4",
    "zone.js": "^0.7.2"
  ,
  "devDependencies": 
    "del": "^2.0.2",
    "gulp": "gulpjs/gulp#4ed9a4a3275559c73a396eff7e1fde3824951ebb",
    "gulp-hub": "frankwallis/gulp-hub#d461b9c700df9010d0a8694e4af1fb96d9f38bf4",
    "gulp-filter": "^4.0.0",
    "gulp-util": "^3.0.7",
    "gulp-sass": "^2.1.1",
    "browser-sync": "^2.18.2",
    "browser-sync-spa": "^1.0.3",
    "karma": "^1.3.0",
    "karma-coverage": "^1.1.1",
    "karma-jasmine": "^1.0.2",
    "karma-junit-reporter": "^1.1.0",
    "jasmine": "^2.4.1",
    "es6-shim": "^0.35.0",
    "karma-chrome-launcher": "^2.0.0",
    "babel-plugin-istanbul": "^3.0.0",
    "karma-webpack": "^1.7.0",
    "webpack": "2.1.0-beta.20",
    "html-webpack-plugin": "^2.24.1",
    "style-loader": "^0.13.0",
    "css-loader": "^0.26.0",
    "postcss-loader": "^1.1.1",
    "autoprefixer": "^6.5.3",
    "json-loader": "^0.5.4",
    "extract-text-webpack-plugin": "^2.0.0-beta.3",
    "html-loader": "^0.4.3",
    "ts-loader": "^1.2.2",
    "sass-loader": "^4.0.2",
    "node-sass": "^3.13.0",
    "eslint": "^3.11.1",
    "eslint-config-xo-space": "^0.15.0",
    "eslint-loader": "^1.6.1",
    "babel-loader": "^6.2.8",
    "babel-eslint": "^7.1.1",
    "eslint-plugin-babel": "^4.0.0",
    "tslint": "^4.0.2",
    "typescript": "^2.0.10",
    "typings": "^2.0.0",
    "tslint-loader": "^3.2.1",
    "codelyzer": "^2.0.0-beta.1"
  ,
  "scripts": 
    "build": "gulp",
    "serve": "gulp serve",
    "serve:dist": "gulp serve:dist",
    "test": "gulp test",
    "test:auto": "gulp test:auto"
  ,
  "eslintConfig": 
    "root": true,
    "env": 
      "browser": true,
      "jasmine": true
    ,
    "extends": [
      "xo-space/esnext"
    ]
  

【问题讨论】:

【参考方案1】:

升级 Angular 项目后我遇到了同样的问题。删除此规则为我解决了这个问题:

"no-misused-new"

【讨论】:

【参考方案2】:

从 Angular 项目中复制规则后,我遇到了同样的问题。 只需创建一个新的空 typescript 项目就可以了。

【讨论】:

【参考方案3】:

截至,codelyzer 2.0.0-beta.1 有一些重大变化。 他们删除了指令选择器名称、组件选择器名称、指令选择器类型、组件选择器类型、指令选择器前缀和组件选择器前缀不再受支持。相反,他们添加了以下规则:

"directive-selector": [true, "attribute", "app", "camelCase"],
"component-selector": [true, "element", "app", "kebab-case"],

请查看 changelog 的 codelyzer 并搜索任何不支持的规则

【讨论】:

【参考方案4】:

我的 IDE WebStorm 2016.x 中出现 Could not find implementations for the following rules... 警告时遇到了同样的问题。在我的例子中,规则实现是由 IDE 提供的,因为升级我的 WebStorm 解决了这个问题。

我升级了 Typescript、TSLint 和 Codelyzer,但无济于事。我检查了 tslint.json 文件的内容,但一无所获。升级 WebStorm 解决了这个问题。

【讨论】:

【参考方案5】:

我在同一条船上。我不知道你以前的 tslint 版本是什么,但是,对我来说,我从 3.15.1 升级到了 4.0.2,我得到的“破坏规则”列表与你的不同。不过,我可以为您和我的共同点提供一些修复/解释。

我刚刚去了tslint's changelog on GitHub,找到了被破坏的规则,得到了行尾的问题编号,并查找了问题。最简单的导航方式是将问题编号添加到其 GitHub 问题 URL 的末尾。例如,label-undefined 是 http//github.com/palantir/tslint/issues/877

这是我必须弄清楚的那些

label-undefined -> typescript 编译器现在处理这个问题,所以从 tslint.json 中删除 "label-undefined": true 然后将 "allowUnusedLabels": false 添加到 tsconfig.json 的 compilerOptions 部分 no-constructor-vars -> 重命名规则,因此在 tslint.json 中将 "no-constructor-vars" 更改为 "no-parameter-properties" no-duplicate-key -> 完全删除"no-duplicate-key": true b/c typescript 现在可以处理它(如果复制键将不会编译)。 no-unreachable -> typescript 编译器现在处理这个问题,所以从 tslint.json 中删除 "no-unreachable": true 然后将 "noImplicitReturns": true 添加到 tsconfig.json 的 compilerOptions 部分 use-strict -> 完全删除 "use-strict" 规则 b/c typescript 现在以严格模式解析所有模块主体。

【讨论】:

仍然有用的解决方案并且解释得很好!【参考方案6】:

tslint v4 删除了一堆不再有意义的规则,TypeScript 检查变得更好。如果您仍想使用这些规则,则需要使用 tslint v3。

【讨论】:

以上是关于更新 TSLint 错误:找不到配置中指定的以下规则的实现的主要内容,如果未能解决你的问题,请参考以下文章

我的数据库系统找不到在 asp.net 中指定的文件

“LIB 环境变量”中指定的搜索路径 *** 无效 --“系统找不到指定的路径。”

FindResource函数错误代码:1813-找不到映像文件中指定的资源类型 与LoadResource函数错误代码:1812-指定的映像文件不包含资源区域

点击IE游览器显示找不到映像文件中指定的资源语言标识McShield

{WinError 2}在使用python编码时,系统找不到Sublime文本中指定的文件

找不到映像文件中指定的资源类型 GetLastError 1813