Package detail

typescript-tslint-plugin

microsoft75kMITdeprecated1.0.2

TSLint has been deprecated in favor of ESLint. This plugin has also been deprecated in favor of ESLint's tooling

TypeScript tslint language service plugin

readme

TypeScript TSLint Language Service Plugin

Build Status

❗IMPORTANT: TSLint has been deprecated in favor of ESLint and this plug-in has also been deprecated in favor of eslint.

Please look into migrating your projects to ESLint.

TypeScript language service plugin for TSLint.

To use the plugin:

  • Install TSLint 5+ in your workspace or globally (if you are using a local TSLint, see workspace library execution)

  • Install the plugin with npm install typescript-tslint-plugin

  • Enable the plugin in your tsconfig.json file:

      {
        "compilerOptions": {
          "plugins": [
            { "name": "typescript-tslint-plugin" }
          ]
        }
      }

See editor support for more detailed setup instructions.

Workspace Library Execution

By default this plugin will not load TSLint or custom rules from the workspace if you are using a global version of TypeScript. This is done for security reasons. The plugin always allows using the global version of TSLint.

To use enable using a local TSLint install and custom rules from the workspace, you must either:

  • Use a workspace version of TypeScript that is installed alongside TSLint.

  • Enable workspace library execution in your editor of choice. This must be done through an editor and cannot be configured in a tsconfig.

    In VS Code for example, you can run the TSLint: Manage Workspace Library Execution command to enable using the TSLint for the current workspace or for all workspaces.

  • Set a TS_TSLINT_ENABLE_WORKSPACE_LIBRARY_EXECUTION=1 environment variable and make sure the TypeScript server is run in an environment where this variable is set to true.

Configuration options

Notice: This configuration settings allow you to configure the behavior of the typescript-tslint-plugin itself. To configure rules and tslint options you should use the tslint.json file.

  • configFile - The configuration file that tslint should use instead of the default tslint.json. A relative file path is resolved relative to the project root.
  • jsEnable - Enable/disable tslint for .js files, default is false.
  • ignoreDefinitionFiles - Control if TypeScript definition files should be ignored. Default is true
  • alwaysShowRuleFailuresAsWarnings - Always show rule failures as warnings, ignoring the severity configuration in the tslint.json configuration. Default is true.
  • suppressWhileTypeErrorsPresent - Suppress tslint errors from being reported while other errors are present.
  • exclude - List of files to exclude from tslint.
  • packageManager - Package manager used, either: npm, yarn, or pnpm. This is currently only used for error message instructions about how to install tslint. Default is npm.

Here is a configuration sample:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-tslint-plugin",
        "alwaysShowRuleFailuresAsWarnings": false,
        "ignoreDefinitionFiles": true,
        "configFile": "../tslint.json",
        "suppressWhileTypeErrorsPresent": false
      }
    ]
  }
}

Notice: due to an issue in the implementation of the no-unused-variable rule (palantir/tslint#2469), this rule will be disabled by the plugin. You can use the typescript compiler options noUnusedLocals and noUnusedParameters instead.

Editor Support

This plugin requires TypeScript 3.0 or later. It can provide intellisense in both JavaScript and TypeScript files within any editors that uses TypeScript to power their language features.

With VS Code

If you also have the vscode-tslint extension in VS Code installed, please disable it to avoid that files are linted twice.

The simplest way to use this plugin is to install the TypeScript TSLint Plugin VS Code extension. This extension enables the plugin when using VS Code's version of TypeScript.

If you are using a workspace version of TypeScript, you must manually install the plugin alongside the version of TypeScript in your workspace:

npm install --save-dev typescript-tslint-plugin typescript

Then add a plugins section to your tsconfig.json or jsconfig.json

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-tslint-plugin"
      }
    ]
  }
}

Finally, run the Select TypeScript version command in VS Code to switch to use the workspace version of TypeScript for VS Code's JavaScript and TypeScript language support. You can find more information about managing typescript versions in the VS Code documentation.

Usage with VS Code

The most important differences between the vscode-tslint extension and typescript-tslint-plugin are:

  • The plugin shares the program representation with TypeScript. This is more efficient than the vscode-tslint extension which needs to reanalyze the document.
  • Since vscode-tslint lints one file a time only, it cannot support tslint rules that require the type checker. The plugin doesn't have this limitation.
  • vscode-tslint provides additional features, please file issue requests for the features you are missing.

With Atom

This plugin works with the Atom TypeScript plugin.

First install the plugin and a copy of TypeScript in your workspace:

npm install --save-dev typescript-tslint-plugin typescript

Then add a plugins section to your tsconfig.json or jsconfig.json and restart Atom.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-tslint-plugin"
      }
    ]
  }
}

Usage with atom

With Sublime

This plugin works with the Sublime TypeScript plugin.

First install the plugin and a copy of TypeScript in your workspace:

npm install --save-dev typescript-tslint-plugin typescript

And configure Sublime to use the workspace version of TypeScript by setting the typescript_tsdk setting in Sublime:

{
  "typescript_tsdk": "/Users/me/my-amazing-project/node_modules/typescript/lib"
}

Finally add a plugins section to your tsconfig.json or jsconfig.json and restart Sublime.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-tslint-plugin"
      }
    ]
  }
}

Usage with Sublime

With Visual Studio

This plugin works Visual Studio 2017 using the TypeScript 2.5+ SDK.

First install the plugin in your project:

npm install --save-dev typescript-tslint-plugin

Then add a plugins section to your tsconfig.json.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-tslint-plugin"
      }
    ]
  }
}

Then reload your project to make sure the plugin has been loaded properly. Note that jsconfig.json projects are currently not supported in Visual Studio.

With vim and neovim

Use coc-tslint-plugin as extension of coc.nvim.

Run command in your vim after coc.nvim installed:

:CocInstall coc-tsserver coc-tslint-plugin

Run command :CocConfig to open configuration file.

Contributing

To build the typescript-tslint-plugin, you'll need Git and Node.js.

First, fork the typescript-tslint-plugin repo and clone your fork:

git clone https://github.com/YOUR_GITHUB_ACCOUNT_NAME/typescript-tslint-plugin.git
cd typescript-tslint-plugin

Then install dev dependencies:

npm install

The plugin is written in TypeScript. The source code is in the src/ directory with the compiled JavaScript output to the lib/ directory. Kick off a build using the compile script:

npm run compile

Please also see our Code of Conduct.

VS Code

To test the newly compiled program, open the test-workspace folder in VS Code and use the TypeScript version picker to switch to the local version of TypeScript.

To debug you use two versions of VS Code, e.g., the stable and the insider version. The idea is that one of them is configured to support attaching a debugger to the Typescript language server:

  • Use the insider version for development and open it on the typescript-tslint-plugin workspace.
  • Use the stable version for debugging opened on the test-workspace folder of the tslint-language service.

To setup the stable version for debugging, you need to set the environment variable TSS_DEBUG to port 5859. In a command prompt/shell:

  • make sure that the stable version isn't running already
  • set TSS_DEBUG=5859
  • cd to the dev folder
  • code .

To debug the plugin press F5. The dev workspace has a launch configuration that attaches through port 5859 to the language server.

Credits

This project was forked from https://github.com/angelozerr/tslint-language-service which itself is based on https://github.com/Microsoft/vscode-tslint/

changelog

Changelog

1.0.2 - March 31, 2022

  • Deprecate package as eslint is now preferred for TypeScript linting.
  • Try ignoring in-memory files which can crash tslint.

1.0.1 - December 14, 2020

  • Catch error when resolving global tslint fails. Thanks @nickjs!

1.0.0 - November 30, 2020

  • Restricts when tslint is loaded from the workspace. This fix was made in response to CVE-2020-17150.
    • Global TSLint versions can always be loaded.
    • TSLint versions installed next to the plugin can always be loaded.
    • Otherwise, the consumer of the plugin must use onConfigurationChanged and explicitly enable allowWorkspaceLibraryExecution.
    • You can also force allow workspace versions of TSLint to be loaded by setting a TS_TSLINT_ENABLE_WORKSPACE_LIBRARY_EXECUTION environment variable.

0.5.5 - November 11, 2019

  • Restore old cwd after linting finishes.

0.5.4 - July 10, 2019

  • Make sure we pass along packageManager from plugin.

0.5.3 - June 28, 2019

  • Fixed the disable quick fix not having correct indentation.

0.5.2 - June 21, 2019

  • Fixes the config file diagnostic not having tslint as its source.

0.5.1 - June 21, 2019

  • Fixes mjs files being linted by default.

0.5.0 - June 10, 2019

  • Add pnpm as packageManager option.

0.4.0 - May 21, 2019

  • Try to help users better understand why tslint is not enabled by generating warnings if there is a tslint.json and the tslint library cannot be found or generates an error.

0.3.1 - January 31, 2019

  • Fix the fix-all action show up even on non-autofixable errors.

0.3.0 - January 21, 2019

  • Set fixName on returned actions. Thanks @kondi!
  • Fix TS Lint's fix all quick fix showing up on non-tslint errors.
  • Use getCombinedQuickFixes to compute 'fix all of X' errors.

0.2.1 - December 14, 2018

  • Fix ignoreDefinitionFiles defaulting to false.

0.2.0 - December 12, 2018

  • Allowing configuring excluded files. Thanks @vemoo!
  • Default alwaysShowRuleFailuresAsWarnings to true. Set "alwaysShowRuleFailuresAsWarnings": false to restore the old behavior.
  • Removing logic for older TS lint versions. Only TSlint5 was ever officially supported but there was still some logic for handling older tslint4.
  • Don't show error in editor if tslint can't be found. We still log an error in the TS Server but do not generate an editor warning.

0.1.2 - November 28, 2018

  • Always show a disable rule fix for TSLint errors. Thanks @reduckted!

0.1.1 - November 27, 2018

  • Fix bug that could cause TS Lint to use a different version of TypeScript than the version being used by the plugin. This would result in unexpected behavior.

0.1.0 - November 16, 2018

  • Add support for configuring the plugin from an editor.
  • Correctly observe changes to the tsconfig/jsconfig.
  • Fix error that could cause duplicate tslint errors to be reported.

0.0.7 - November 15, 2018

  • Fix potential state corruption error when using TS 3.2.

0.0.6 - November 13, 2018

  • Add enableJs option to enable/disable validating js. Default to false.

0.0.5 - November 5, 2018

  • Use diagnostic as label for quick fixes
  • Enable for js files included in tsconfig.

0.0.4 - October 23, 2018

  • Fix spelling of setting name

0.0.3 - October 22, 2018

  • Don't call getProgram directly since it may corrupt the TS Server state
  • Exclude some files from npm package.

0.0.2 - October 19, 2018

  • Initial release