Top Related Projects
:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript
A mighty CSS linter that helps you avoid errors and enforce conventions.
Prettier is an opinionated code formatter.
Find and fix problems in your JavaScript code.
Adds static typing to JavaScript to improve developer productivity and code quality.
Quick Overview
TSLint is an extensible static analysis tool for TypeScript and JavaScript code. It checks your code for readability, maintainability, and functionality errors, and can be customized with your own lint rules, configurations, and formatters.
Pros
- Highly configurable with a wide range of built-in rules
- Extensible architecture allowing custom rules and plugins
- Integrates well with popular IDEs and build tools
- Helps maintain consistent code style across projects
Cons
- Deprecated in favor of ESLint with TypeScript support
- Performance can be slow on large codebases
- Some rules may conflict with each other or with TypeScript compiler checks
- Learning curve for creating custom rules
Code Examples
- Basic TSLint configuration (tslint.json):
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"no-console": false
},
"rulesDirectory": []
}
- Custom TSLint rule:
import * as ts from "typescript";
import * as Lint from "tslint";
export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "Avoid using 'var' keyword";
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoVarWalker(sourceFile, this.getOptions()));
}
}
class NoVarWalker extends Lint.RuleWalker {
public visitVariableStatement(node: ts.VariableStatement) {
if (node.declarationList.flags & ts.NodeFlags.Let) {
this.addFailureAtNode(node, Rule.FAILURE_STRING);
}
super.visitVariableStatement(node);
}
}
- Running TSLint from command line:
tslint -c tslint.json 'src/**/*.ts'
Getting Started
-
Install TSLint and TypeScript:
npm install tslint typescript --save-dev
-
Create a TSLint configuration file (tslint.json) in your project root:
{ "defaultSeverity": "error", "extends": [ "tslint:recommended" ], "jsRules": {}, "rules": {}, "rulesDirectory": [] }
-
Run TSLint on your TypeScript files:
npx tslint -c tslint.json 'src/**/*.ts'
Competitor Comparisons
:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript
Pros of typescript-eslint
- Better integration with ESLint ecosystem and plugins
- More actively maintained and updated
- Supports newer TypeScript features more quickly
Cons of typescript-eslint
- Steeper learning curve for configuration
- Potentially slower performance due to more complex parsing
Code Comparison
typescript-eslint configuration:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"]
}
TSLint configuration:
{
"extends": ["tslint:recommended"],
"rules": {
"no-console": false
}
}
Additional Notes
typescript-eslint has become the preferred linting solution for TypeScript projects, as TSLint has been deprecated. The typescript-eslint project offers more flexibility and better integration with the broader JavaScript ecosystem. However, it may require more setup and configuration compared to TSLint's simpler approach.
typescript-eslint provides a more comprehensive set of rules and is better suited for large-scale projects with complex linting requirements. It also allows for easier customization and creation of custom rules.
While TSLint was specifically designed for TypeScript, typescript-eslint leverages the power of ESLint while providing full TypeScript support, making it a more versatile choice for projects that use both JavaScript and TypeScript.
A mighty CSS linter that helps you avoid errors and enforce conventions.
Pros of stylelint
- Actively maintained and regularly updated
- Supports a wide range of CSS preprocessors (Sass, Less, SugarSS)
- Extensive plugin ecosystem for custom rules and integrations
Cons of stylelint
- Limited to CSS and CSS-like languages
- Steeper learning curve for complex configurations
- May require additional setup for certain preprocessors
Code Comparison
stylelint configuration example:
{
"extends": "stylelint-config-standard",
"rules": {
"indentation": 2,
"color-hex-case": "lower"
}
}
TSLint configuration example:
{
"extends": "tslint:recommended",
"rules": {
"indent": [true, "spaces", 2],
"quotemark": [true, "single"]
}
}
Additional Notes
While stylelint focuses on CSS and related languages, TSLint was specifically designed for TypeScript. However, it's worth noting that TSLint has been deprecated in favor of ESLint with TypeScript support. stylelint remains the go-to tool for CSS linting, while ESLint has become the preferred choice for JavaScript and TypeScript linting.
Prettier is an opinionated code formatter.
Pros of Prettier
- Opinionated formatting with minimal configuration options, leading to consistent code style across projects
- Supports multiple languages beyond TypeScript, including JavaScript, CSS, and more
- Integrates seamlessly with various editors and IDEs
Cons of Prettier
- Less flexible in terms of customization compared to TSLint
- Focuses primarily on code formatting, not linting for potential errors or best practices
Code Comparison
TSLint configuration:
{
"rules": {
"semicolon": [true, "always"],
"quotemark": [true, "single"]
}
}
Prettier configuration:
{
"semi": true,
"singleQuote": true
}
Additional Notes
- TSLint is specifically designed for TypeScript, while Prettier is language-agnostic
- Prettier aims to reduce debates about code style by providing a single, opinionated format
- TSLint offers more granular control over linting rules and can catch potential errors
- Many developers use both tools in combination, with Prettier handling formatting and TSLint focusing on code quality
It's worth noting that TSLint has been deprecated in favor of ESLint with TypeScript support, so comparing Prettier to ESLint might be more relevant for current projects.
Find and fix problems in your JavaScript code.
Pros of ESLint
- Supports both JavaScript and TypeScript, offering broader language coverage
- More active development and larger community, resulting in frequent updates and extensive plugin ecosystem
- Provides autofix capabilities for many rules, improving code quality automatically
Cons of ESLint
- Requires additional configuration for TypeScript support, which can be complex for beginners
- May have slower performance compared to TSLint when analyzing large TypeScript projects
Code Comparison
ESLint configuration example:
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"no-unused-vars": "error"
}
}
TSLint configuration example:
{
"extends": ["tslint:recommended"],
"rules": {
"no-unused-variable": true
}
}
Both ESLint and TSLint offer powerful linting capabilities for TypeScript projects. ESLint has become the more popular choice due to its versatility and active development. However, TSLint may still be preferred in some TypeScript-specific scenarios or for projects with existing TSLint configurations. It's worth noting that the TypeScript team now recommends using ESLint for TypeScript projects, as TSLint is no longer actively maintained.
Adds static typing to JavaScript to improve developer productivity and code quality.
Pros of Flow
- Static type checking for JavaScript, providing more comprehensive type analysis
- Supports gradual typing, allowing incremental adoption in existing projects
- Integrates well with React and other Facebook technologies
Cons of Flow
- Steeper learning curve compared to TSLint
- Requires additional setup and configuration
- Less widespread adoption in the JavaScript community
Code Comparison
Flow:
// @flow
function add(x: number, y: number): number {
return x + y;
}
TSLint:
function add(x: number, y: number): number {
return x + y;
}
While both examples show type annotations, Flow requires an explicit comment to enable type checking, whereas TSLint works with TypeScript files by default.
Flow provides more advanced type inference and analysis, but TSLint offers simpler setup and wider community support. Flow is better suited for large-scale JavaScript projects, especially those using React, while TSLint is more appropriate for TypeScript-based projects or those seeking straightforward linting capabilities.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
TSLint
:warning: TSLint is deprecated.
See this issue for more details: Roadmap: TSLint → ESLint. If you're interested in helping with the TSLint/ESLint migration, check out the typescript-eslint roadmap.
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 currently supports:
- an extensive set of core rules
- custom lint rules
- custom formatters (failure reporters)
- inline disabling and enabling of rules with comment flags in source code
- configuration presets (
tslint:latest
,tslint-react
, etc.) and plugin composition - automatic fixing of formatting & style violations
- integration with MSBuild, Grunt, Gulp, Atom, Eclipse, Emacs, Sublime, Vim, Visual Studio 2015, Visual Studio 2017, Visual Studio code (alternative: use this extension for TS <3.2), WebStorm and more
Installation & Usage
Please refer to the full installation & usage documentation on the TSLint website. There, you'll find information about
- configuration,
- core rules,
- core formatters, and
- customization of TSLint.
- inline disabling and enabling of rules with comment flags
TSLint Playground
There is a sandbox environment for TSLint at palantir.github.io/tslint-playground, which can be used to test rules and see how TSLint works. Issues can be filed against tslint-playground
here.
Custom Rules & Plugins
Custom rule sets from Palantir
- tslint-react - Lint rules related to React & JSX.
- tslint-blueprint - Lint rules to enforce best practices with blueprintjs libraries
Custom rule sets from the community
If we don't have all the rules you're looking for, you can either write your own custom rules or use rules implementations developed by the community. The repos below are a good source of custom rules:
- ESLint rules for TSLint - Improve your TSLint with the missing ESLint Rules
- tslint-microsoft-contrib - A set of TSLint rules used on some Microsoft projects
- codelyzer - A set of tslint rules for static code analysis of Angular TypeScript projects
- vrsource-tslint-rules
- tslint-immutable - TSLint rules to disable mutation in TypeScript
- tslint-consistent-codestyle - TSLint rules to enforce consistent code style in TypeScript
- tslint-sonarts - Bug-finding rules based on advanced code models to spot hard to find errors in TypeScript
- tslint-clean-code - A set of TSLint rules inspired by the Clean Code handbook
- rxjs-tslint-rules - TSLint rules for RxJS
Development
Prerequisites:
node
v7+yarn
v1.0+
Quick Start
git clone git@github.com:palantir/tslint.git --config core.autocrlf=input --config core.eol=lf
yarn
yarn compile
yarn test
Top Related Projects
:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript
A mighty CSS linter that helps you avoid errors and enforce conventions.
Prettier is an opinionated code formatter.
Find and fix problems in your JavaScript code.
Adds static typing to JavaScript to improve developer productivity and code quality.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot