tsgolint: An Experimental Go-Powered Linter for TypeScript/JavaScript

Summary
tsgolint is an experimental proof-of-concept linter for JavaScript and TypeScript, leveraging typescript-go and written in Go. It aims to explore significant performance improvements, demonstrating a 20-40x speedup over ESLint + typescript-eslint by using native parsing, direct TS AST usage, and parallel processing. While a prototype not under active development, it showcases the potential for faster typed linting.
Repository Info
Tags
Click on any tag to explore related repositories
Introduction
tsgolint is an experimental proof-of-concept linter for JavaScript and TypeScript, developed by the typescript-eslint team. Written in Go and powered by the typescript-go project, its primary goal is to investigate new architectures and performance characteristics for linting. It serves as a prototype to explore how much faster linting could be by moving the linter to Go alongside typescript-go.
It's important to note that tsgolint is in its early stages of development, is not actively being worked on, and is not expected to be production-ready. However, it successfully prototypes a primitive linter engine, a rules tester, a source code fixer, and implements 40 type-aware typescript-eslint rules.
Installation
To build tsgolint from source, follow these steps:
git submodule update --init # init typescript-go submodule
cd typescript-go
git am --3way --no-gpg-sign ../patches/*.patch # apply typescript-go patches
cd ..
go build -o tsgolint ./cmd/tsgolint
Examples
tsgolint has successfully prototyped the implementation of 40 type-aware rules from typescript-eslint. These rules cover various aspects of code quality and potential issues in TypeScript and JavaScript projects. For a complete list of implemented rules, please refer to the project's GitHub README. While a basic CLI is available, tsgolint primarily focuses on demonstrating the underlying performance benefits rather than offering a rich set of command-line features or editor integrations at this experimental stage.
Why Use tsgolint (as an experiment)
The most compelling aspect of tsgolint is its remarkable performance. Benchmarks indicate that tsgolint is 20-40 times faster than ESLint combined with typescript-eslint. This significant speedup is attributed to several key factors:
- Native Speed Parsing and Type-Checking: Leveraging typescript-go,
tsgolintbenefits from native Go performance for parsing and type-checking JavaScript and TypeScript code. - Direct TS AST Usage: Unlike traditional setups that might involve conversions from TypeScript AST to ESTree AST,
tsgolintdirectly uses the TypeScript AST in its rules, eliminating overhead. - Parallel Processing:
tsgolintis designed to utilize all available CPU cores for parallel parsing, type-checking, and linting, further enhancing its speed.
It's crucial to remember that tsgolint is an experiment to explore these performance boundaries. It is not intended to divert significant development resources from typescript-eslint, which remains the primary focus for typed linting with ESLint. This project serves as a valuable research tool to understand the potential of Go-based linting solutions.
Links
- GitHub Repository: https://github.com/typescript-eslint/tsgolint
- typescript-go Project: https://github.com/microsoft/typescript-go
- typescript-eslint Blog on ASTs: https://typescript-eslint.io/blog/asts-and-typescript-eslint/#ast-formats
- typescript-eslint Issue for tsgo Integration: https://github.com/typescript-eslint/typescript-eslint/issues/10940