typescript-eslint
:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript
Top Related Projects
Find and fix problems in your JavaScript code.
:vertical_traffic_light: An extensible linter for the TypeScript language
Prettier is an opinionated code formatter.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
🌟 JavaScript Style Guide, with linter & automatic code fixer
Quick Overview
TypeScript ESLint is a monorepo that houses ESLint plugins and configurations for TypeScript. It provides a set of ESLint rules specifically designed for TypeScript codebases, along with parser and utilities to enable ESLint to work with TypeScript files.
Pros
- Enhances code quality and consistency in TypeScript projects
- Provides TypeScript-specific linting rules not available in standard ESLint
- Regularly updated to support the latest TypeScript features
- Highly configurable to suit different project needs
Cons
- Can be complex to set up and configure for beginners
- May introduce additional build time due to TypeScript parsing
- Some rules might conflict with TypeScript's own checks
- Occasional breaking changes between major versions
Code Examples
- Basic ESLint configuration for TypeScript:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
]
}
- Using a custom rule:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function example(param: any): void {
console.log(param);
}
- Configuring a specific rule:
{
"rules": {
"@typescript-eslint/explicit-function-return-type": ["error", {
"allowExpressions": true,
"allowTypedFunctionExpressions": true
}]
}
}
Getting Started
- Install the necessary packages:
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
- Create a
.eslintrc.js
file in your project root:
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
// Add custom rules here
},
};
- Add a lint script to your
package.json
:
{
"scripts": {
"lint": "eslint . --ext .ts"
}
}
- Run the linter:
npm run lint
Competitor Comparisons
Find and fix problems in your JavaScript code.
Pros of ESLint
- Broader language support: Works with JavaScript, JSX, and other variants
- Larger ecosystem of plugins and configurations
- More established project with a longer history and wider adoption
Cons of ESLint
- Limited TypeScript support out of the box
- Requires additional setup and plugins for optimal TypeScript linting
- May have performance issues with large TypeScript projects
Code Comparison
ESLint configuration for TypeScript:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"]
}
TypeScript-ESLint configuration:
{
"extends": ["plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": { "project": "./tsconfig.json" }
}
TypeScript-ESLint is specifically designed for TypeScript projects, offering more robust and accurate linting for TypeScript code. It provides better type-aware rules and can catch more TypeScript-specific issues. ESLint, on the other hand, is more versatile and can be used across various JavaScript projects, but requires additional setup for optimal TypeScript support.
Both tools are valuable in their respective domains, with ESLint being more suitable for mixed JavaScript/TypeScript projects or teams transitioning to TypeScript, while TypeScript-ESLint is ideal for dedicated TypeScript projects seeking more comprehensive linting capabilities.
:vertical_traffic_light: An extensible linter for the TypeScript language
Pros of TSLint
- Mature and well-established linter with a large rule set
- Extensive documentation and community support
- Customizable and extensible with custom rules
Cons of TSLint
- Deprecated and no longer actively maintained
- Limited integration with modern TypeScript features
- Slower performance compared to typescript-eslint
Code Comparison
TSLint configuration:
{
"rules": {
"no-unused-variable": true,
"semicolon": [true, "always"]
}
}
typescript-eslint configuration:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"semi": ["error", "always"]
}
}
TSLint has been deprecated in favor of typescript-eslint, which is now the recommended linting solution for TypeScript projects. typescript-eslint offers better performance, improved integration with modern TypeScript features, and active maintenance. It also provides a more consistent experience with ESLint, making it easier to lint both JavaScript and TypeScript code in the same project.
While TSLint still has a large rule set and extensive documentation, its lack of ongoing development means it may not support the latest TypeScript features or receive bug fixes. typescript-eslint, on the other hand, is actively maintained and regularly updated to support new TypeScript versions and features.
Prettier is an opinionated code formatter.
Pros of Prettier
- Opinionated formatting with minimal configuration required
- Supports multiple languages beyond TypeScript (JavaScript, CSS, HTML, etc.)
- Faster performance for large codebases
Cons of Prettier
- Less flexibility in customizing code style rules
- Focuses solely on formatting, not linting or type checking
- May conflict with existing team coding standards
Code Comparison
typescript-eslint:
// .eslintrc.js
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'error',
},
};
Prettier:
// .prettierrc.js
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
};
typescript-eslint is a powerful linting tool specifically designed for TypeScript, offering extensive customization options and type-aware rules. It excels in catching potential errors and enforcing best practices.
Prettier, on the other hand, is a code formatter that aims to eliminate debates about code style by providing a consistent, opinionated format across various languages. It's simpler to set up and use but lacks the depth of linting capabilities found in typescript-eslint.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
Pros of TypeScript
- Official Microsoft project with extensive resources and documentation
- Broader scope, focusing on the entire TypeScript language and ecosystem
- Regular updates and new feature implementations for the language
Cons of TypeScript
- Less specialized for linting and code quality enforcement
- May require additional tools for comprehensive static analysis
- Slower to implement specific linting rules compared to dedicated linting projects
Code Comparison
TypeScript (compiler options):
{
"compilerOptions": {
"strict": true,
"target": "ES2020",
"module": "ESNext"
}
}
typescript-eslint (ESLint configuration):
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
}
Summary
TypeScript focuses on the language itself, providing the compiler and core functionality. It offers comprehensive language support but may require additional tools for specialized linting. typescript-eslint, on the other hand, is dedicated to linting and static analysis for TypeScript projects, offering more granular control over code quality and style enforcement. While TypeScript provides the foundation, typescript-eslint builds upon it to offer enhanced linting capabilities specifically tailored for TypeScript codebases.
❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
Pros of xo
- Simpler setup and configuration with opinionated defaults
- Includes both linting and code formatting in a single package
- Supports a wide range of JavaScript environments (Node.js, browsers, etc.)
Cons of xo
- Less flexibility for customization compared to typescript-eslint
- Limited TypeScript-specific rules and features
- Smaller community and ecosystem compared to typescript-eslint
Code Comparison
xo configuration:
{
"extends": "xo",
"rules": {
"unicorn/no-process-exit": "off"
}
}
typescript-eslint configuration:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
]
}
xo focuses on providing a simple, opinionated setup with minimal configuration, while typescript-eslint offers more granular control and TypeScript-specific features. xo is better suited for projects that prioritize quick setup and consistency across different JavaScript environments, whereas typescript-eslint is ideal for TypeScript projects requiring detailed customization and advanced type-aware linting rules.
🌟 JavaScript Style Guide, with linter & automatic code fixer
Pros of Standard
- Simpler setup and configuration
- Opinionated, "zero-config" approach
- Broader language support (JavaScript, TypeScript, JSX, etc.)
Cons of Standard
- Less flexibility for custom rules
- May not cover all TypeScript-specific linting needs
- Fewer plugin options compared to ESLint ecosystem
Code Comparison
Standard:
module.exports = {
extends: 'standard'
}
TypeScript-ESLint:
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended']
}
Key Differences
-
Configuration: Standard aims for a no-configuration approach, while TypeScript-ESLint offers more granular control.
-
TypeScript Focus: TypeScript-ESLint is specifically designed for TypeScript projects, providing more in-depth TypeScript-specific rules.
-
Ecosystem: TypeScript-ESLint integrates with the broader ESLint ecosystem, allowing for more plugins and customization.
-
Learning Curve: Standard has a lower learning curve due to its simplicity, while TypeScript-ESLint requires more understanding of ESLint and TypeScript.
-
Project Size: Standard is better suited for smaller projects or quick setups, while TypeScript-ESLint shines in larger, more complex TypeScript projects.
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
typescript-eslint
Monorepo for the tooling that enables ESLint and Prettier to support TypeScript
ð
See typescript-eslint.io for documentation on the latest released version.
See main--typescript-eslint.netlify.app for documentation on the latest canary release.
ð
Code Contributors
This project exists thanks to the awesome people who contribute code and documentation:
ð An extra special thanks goes out to the wonderful people listed in CONTRIBUTORS.md
Financial Contributors
In addition to submitting code and documentation updates, you can help us sustain our community by becoming a financial contributor [Click here to contribute - every little bit helps!]
License
typescript-eslint inherits is licensed under a permissive MIT license.
Top Related Projects
Find and fix problems in your JavaScript code.
:vertical_traffic_light: An extensible linter for the TypeScript language
Prettier is an opinionated code formatter.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
🌟 JavaScript Style Guide, with linter & automatic code fixer
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