What is tslint?
The tslint npm package is a static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It is widely used to enforce a consistent code style by checking the code against a set of linting rules.
What are tslint's main functionalities?
Linting TypeScript Files
This feature allows you to lint TypeScript files by specifying a configuration file and a pattern to match files. The command will process all TypeScript files in the 'src' directory and its subdirectories.
tslint -c tslint.json 'src/**/*.ts'
Fixing Linting Errors Automatically
This feature automatically fixes linting errors that can be corrected without human intervention. It is useful for fixing simple issues like whitespace or semicolon usage.
tslint --fix -c tslint.json 'src/**/*.ts'
Custom Rules
This feature allows you to use custom linting rules in addition to the predefined rules. You can specify a directory containing custom rule definitions to be applied to your code.
tslint -c tslint.json 'src/**/*.ts' --rules-dir custom_rules
Other packages similar to tslint
eslint
ESLint is a popular linting tool for JavaScript and TypeScript. It is highly configurable and extendable, with a large ecosystem of plugins. ESLint has effectively replaced TSLint as the preferred linter for TypeScript after TSLint's deprecation.
prettier
Prettier is an opinionated code formatter that supports many languages, including TypeScript. While it does not perform static code analysis, it formats code to a consistent style. Prettier can be used alongside linters like ESLint.
stylelint
Stylelint is a modern linter that helps you avoid errors and enforce conventions in your stylesheets. Although it is primarily used for CSS, it can be used in conjunction with PostCSS to lint SCSS, Sass, Less, and other CSS-like languages.
TSLint
TSLint is an extensible static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It is widely supported across modern editors & build systems and can be customized with your own lint rules, configurations, and formatters.
TSLint supports:
- custom lint rules
- custom formatters (failure reporters)
- inline disabling and enabling of rules
- configuration presets (
tslint:latest
, tslint-react
, etc.) & composition - automatic fixing of formatting & style violations
- integration with msbuild, grunt, gulp, atom, eclipse, emacs, sublime, vim, visual studio, vscode, webstorm, and more
Installation & Usage
Refer to the full installation & usage documentation on the TSLint website.
There, you'll find information about
Custom Rules
Custom rule sets from Palantir
If we don't have all the rules you're looking for, you can either write your own custom rules or use custom rules that others have developed. The repos below are a good source of custom rules:
Development
Requirements:
Quick Start
git clone git@github.com:palantir/tslint.git --config core.autocrlf=input --config core.eol=lf
yarn install
yarn compile
yarn test
Creating a new release
- Bump the version number in
package.json
and src/tslintMulti.ts
- Add release notes in
CHANGELOG.md
yarn verify
to build the latest sources- Commit with message
Prepare release <version>
- Run
npm publish
- Create a git tag for the new release and push it (see existing tags here)