tslint
Analyze TypeScript code for style and potential errors
TLDR
Create TSLint config
Lint on a given set of files
Fix lint issues
Lint with the configuration file in the project root
SYNOPSIS
tslint [options] [files...]
tslint --init
tslint --test rules-directory
PARAMETERS
-c, --config path
Specifies the path to a tslint.json configuration file. If not provided, tslint will search for one in the current directory or parent directories.
-p, --project path
Specifies the path to a tsconfig.json file. When used, tslint will lint all files included in the TypeScript project.
-t, --format formatter
Defines the output format for linting results. Common formatters include stylish, json, pmd, and msbuild.
-r, --rules-dir path
Specifies a directory containing custom linting rules. These rules are loaded in addition to those defined in the configuration file.
-e, --exclude pattern
Excludes files or directories matching the provided glob pattern from linting. Can be specified multiple times.
--fix
Attempts to automatically fix linting errors where possible. Not all rules support auto-fixing.
--force
Forces tslint to exit with a 0 status code even if linting errors are found. Useful in CI/CD environments where a non-zero exit code might halt the build.
--init
Generates a default tslint.json configuration file in the current directory, providing a starting point for rule configuration.
-v, --version
Displays the current version of tslint.
-h, --help
Displays help information and a list of available options.
DESCRIPTION
The tslint command is a static analysis tool used to check TypeScript code for readability, maintainability, and functional errors. It helps enforce a consistent coding style and best practices across a codebase, identifying potential issues before runtime. Users typically define coding rules in a tslint.json configuration file, which the tool then applies to specified TypeScript files or projects.
While powerful, tslint has been officially deprecated by its creators, Palantir, in favor of ESLint with TypeScript support. This transition was driven by ESLint's broader adoption in the JavaScript ecosystem and its more flexible plugin architecture. Although still functional for existing projects, new TypeScript projects are strongly advised to adopt ESLint.
CAVEATS
tslint has been officially deprecated by its creators since 2019. While it remains functional for existing projects, active development has ceased, and no new features or rule updates are being provided.
For new TypeScript projects, migrating to ESLint with the typescript-eslint parser and plugins is the recommended approach, as it offers a more robust and actively maintained linting solution for TypeScript.
CONFIGURATION FILES
tslint relies heavily on a tslint.json file to define its linting rules and configurations. This JSON file specifies which rules are enabled, their severity (e.g., warning, error), and any specific options for those rules. It can extend configurations from other shared tslint.json files and include or exclude specific files. The --init option can generate a basic configuration file to get started.
RULE SETS
tslint provides a comprehensive set of built-in rules covering various aspects of code quality, from formatting and style to potential bugs. Users can choose to enable or disable these rules and configure their behavior. Additionally, it supports custom rules, allowing developers to enforce project-specific coding standards or integrate with internal tools.
HISTORY
tslint was created by Palantir and quickly became the de facto standard linter for TypeScript projects after its initial release. It gained significant popularity due to TypeScript's growing adoption and the need for code quality enforcement.
However, with the rise of ESLint's ecosystem and its increasing support for parsing various JavaScript dialects (including TypeScript via plugins), Palantir decided to officially deprecate tslint in 2019. They encouraged users to migrate to ESLint, recognizing the community's preference for a unified linting solution across JavaScript and TypeScript codebases. This decision marked a significant shift, leading to the development of typescript-eslint, which effectively became the successor for TypeScript linting.