Convert Figma logo to code with AI

palantir logotslint

:vertical_traffic_light: An extensible linter for the TypeScript language

5,909
890
5,909
1

Top Related Projects

:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript

10,976

A mighty CSS linter that helps you avoid errors and enforce conventions.

49,046

Prettier is an opinionated code formatter.

24,850

Find and fix problems in your JavaScript code.

22,079

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

  1. Basic TSLint configuration (tslint.json):
{
  "defaultSeverity": "error",
  "extends": [
    "tslint:recommended"
  ],
  "jsRules": {},
  "rules": {
    "no-console": false
  },
  "rulesDirectory": []
}
  1. 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);
  }
}
  1. Running TSLint from command line:
tslint -c tslint.json 'src/**/*.ts'

Getting Started

  1. Install TSLint and TypeScript:

    npm install tslint typescript --save-dev
    
  2. Create a TSLint configuration file (tslint.json) in your project root:

    {
      "defaultSeverity": "error",
      "extends": [
        "tslint:recommended"
      ],
      "jsRules": {},
      "rules": {},
      "rulesDirectory": []
    }
    
  3. 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.

10,976

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.

49,046

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.

24,850

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.

22,079

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

NPM version Downloads Dependency Status devDependency Status peerDependency Status Circle CI

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:

Installation & Usage

Please refer to the full installation & usage documentation on the TSLint website. There, you'll find information about

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

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:

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

NPM DownloadsLast 30 Days