Search code examples
javascriptangularvisual-studio-codephpstormtslint

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.

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.

However, PhpStorm does not point out all the errors included in the "angular-tslint-rules" package. I have an example with the rule prefer-readonly. On PhpStorm nothing is underlined as you can see:

PhpStorm

In Vscode the same code is underlined with the error "prefer-readonly" as you can see :

VSCode

So why isn't PhpStorm pointing out the error to me ? Do you have any possible solutions?

Thanks for your help.


Solution

  • 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. While it may look that tslint --project executes quickly when checking files before commit, the IDE needs to be more responsive when editing code.

    To work out the issue, we recommend using typescript-tslint-plugin. To use it:

    • install the 'typescript-tslint-plugin' npm package and add it to 'plugins' in tsconfig.json:
        {
        "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. For additional configuration options, please see the typescript-tslint-plugin docs.

    • make sure to enable Typescript language service in Preferences | Languages and Frameworks | TypeScript