简体   繁体   English

为什么 PhpStorm 不显示所有 TSLint 规则?

[英]Why doesn't PhpStorm show all TSLint rules?

I am having a problem on PhpStorm (v2020.2.1 Build # PS-202.6948.87) and TSLint on an Angular project.我在 PhpStorm (v2020.2.1 Build # PS-202.6948.87) 和 Angular 项目的 TSLint 上遇到问题。

Indeed, I installed the "angular-tslint-rules" package, activated the automatic configuration of TSLint in the settings of PhpStorm in order to have the cleanest possible code.确实,我安装了“angular-tslint-rules”包,在 PhpStorm 的设置中激活了 TSLint 的自动配置,以便拥有最干净的代码。

However, PhpStorm does not point out all the errors included in the "angular-tslint-rules" package.但是,PhpStorm 并未指出“angular-tslint-rules”包中包含的所有错误。 I have an example with the rule prefer-readonly .我有一个带有规则prefer-readonly的示例。 On PhpStorm nothing is underlined as you can see:如您所见,在 PhpStorm 上没有任何下划线:

PhpStorm

In Vscode the same code is underlined with the error "prefer-readonly" as you can see :在 Vscode 中,相同的代码带有错误“prefer-readonly”下划线,如您所见:

VS代码

So why isn't PhpStorm pointing out the error to me ?那么为什么 PhpStorm 不向我指出错误呢? Do you have any possible solutions?你有任何可能的解决方案吗?

Thanks for your help.谢谢你的帮助。

prefer-readonly rule requires type info .首选只读规则需要类型信息 Such rules are not currently supported by TSLint integration because of some technical difficulties: running TSLint with --project tsconfig.json (required for such rules to work) would not be acceptable for us because it would cause a second instance of TypeScript to be created inside the TSLint process (in addition to the TypeScript instance used for compilation and highlighting, if you have it enabled) and would cause a noticeable performance degradation.由于一些技术困难,TSLint 集成目前不支持此类规则:使用--project tsconfig.json (此类规则工作所需)运行 TSLint 对我们来说是不可接受的,因为它会导致创建第二个 TypeScript 实例在 TSLint 进程内部(除了用于编译和突出显示的 TypeScript 实例,如果您启用了它)并且会导致明显的性能下降。 While it may look that tslint --project executes quickly when checking files before commit, the IDE needs to be more responsive when editing code.虽然看起来tslint --project在提交前检查文件时执行速度很快,但 IDE 在编辑代码时需要更灵敏。

To work out the issue, we recommend using typescript-tslint-plugin .为了解决这个问题,我们建议使用typescript-tslint-plugin To use it:要使用它:

  • install the 'typescript-tslint-plugin' npm package and add it to 'plugins' in tsconfig.json:安装'typescript-tslint-plugin' npm 包并将其添加到 tsconfig.json 中的'plugins':
    {
    "compilerOptions": {
    "plugins": [{"name": "typescript-tslint-plugin"}]
    }
    }
  • disable TSLint in the IDE settings ( Preferences | Languages & Frameworks | TypeScript | TSLint ) to avoid the same errors being shown twice.在 IDE 设置( Preferences | Languages & Frameworks | TypeScript | TSLint )中禁用 TSLint 以避免相同的错误显示两次。 For additional configuration options, please see the typescript-tslint-plugin docs .有关其他配置选项,请参阅typescript-tslint-plugin 文档

  • make sure to enable Typescript language service in Preferences |确保在首选项中启用 Typescript 语言服务| Languages and Frameworks |语言和框架 | TypeScript打字稿

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

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