- Saved searches
- Use saved searches to filter your results more quickly
- License
- eslint/typescript-eslint-parser
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Getting Started
- Step 1: Installation
- Step 2: Configuration
- Step 3: Running ESLint
- Details
- Next Steps
- Documentation Resources
- This package has been deprecated
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
License
eslint/typescript-eslint-parser
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Deprecated: TypeScript ESLint Parser
Important: This repository is no longer maintained and typescript-eslint-parser will not receive any future updates. There is an actively maintained fork of this project available at https://typescript-eslint.io and published on npm as @typescript-eslint/parser .
- typescript-eslint-parser + @typescript-eslint/parser
An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
npm install --save-dev typescript-eslint-parser
In your ESLint configuration file, set the parser property:
< "parser": "typescript-eslint-parser" >
There is sometimes an incorrect assumption that the parser itself is what does everything necessary to facilitate the use of ESLint with TypeScript. In actuality, it is the combination of the parser and one or more plugins which allow you to maximize your usage of ESLint with TypeScript.
For example, once this parser successfully produces an AST for the TypeScript source code, it might well contain some information which simply does not exist in a standard JavaScript context, such as the data for a TypeScript-specific construct, like an interface .
The core rules built into ESLint, such as indent have no knowledge of such constructs, so it is impossible to expect them to work out of the box with them.
Instead, you also need to make use of one more plugins which will add or extend rules with TypeScript-specific features.
By far the most common case will be installing the eslint-plugin-typescript plugin, but there are also other relevant options available such a eslint-plugin-tslint.
The following additional configuration options are available by specifying them in parserOptions in your ESLint configuration file.
- jsx — default false . Enable parsing JSX when true . More details can be found here.
- It’s false on *.ts files regardless of this option.
- It’s true on *.tsx files regardless of this option.
- Otherwise, it respects this option.
< "parser": "typescript-eslint-parser", "parserOptions": < "jsx": true, "useJSXTextNode": true > >
Supported TypeScript Version
We will always endeavor to support the latest stable version of TypeScript.
The version of TypeScript currently supported by this parser is ~3.2.1 . This is reflected in the devDependency requirement within the package.json file, and it is what the tests will be run against. We have an open peerDependency requirement in order to allow for experimentation on newer/beta versions of TypeScript.
If you use a non-supported version of TypeScript, the parser will log a warning to the console.
Please ensure that you are using a supported version before submitting any issues/bug reports.
We have a very flexible way of running integration tests which connects all of the moving parts of the usage of this parser in the ESLint ecosystem.
We run each test within its own docker container, and so each one has complete autonomy over what dependencies/plugins are installed and what versions are used. This also has the benefit of not bloating the package.json and node_modules of the parser project itself.
If you are going to submit an issue related to the usage of this parser with ESLint, please consider creating a failing integration test which clearly demonstrates the behavior. It’s honestly super quick!
You just need to duplicate one of the existing test sub-directories found in tests/integration/ , tweak the dependencies and ESLint config to match what you need, and add a new entry to the docker-compose.yml file which matches the format of the existing ones.
If you ever need to change what gets installed when the docker images are built by docker-compose, you will first need to kill the existing containers by running:
npm run kill-integration-test-containers
- npm test — run all linting and tests
- npm run lint — run all linting
- npm run integration-tests — run only integration tests
TypeScript ESLint Parser is licensed under a permissive BSD 2-clause license.
About
An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
Getting Started
These steps will get you running ESLint with our recommended rules on your TypeScript code as quickly as possible.
Step 1: Installation
First, install the required packages for ESLint, TypeScript, and this plugin:
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript
yarn add --dev @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript
pnpm add --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript
Step 2: Configuration
Next, create a .eslintrc.cjs config file in the root of your project, and populate it with the following:
/* eslint-env node */ module.exports = extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint'], root: true, >;
If your project doesn’t use ESM, naming the file as .eslintrc.js is fine. See ESLint’s Configuration Files docs for more info.
Step 3: Running ESLint
Open a terminal to the root of your project and run the following command:
ESLint will lint all TypeScript compatible files within the current folder, and will output the results to your terminal.
Details
- parser: ‘@typescript-eslint/parser’ tells ESLint to use the @typescript-eslint/parser package you installed to parse your source files.
- This is required, or else ESLint will throw errors as it tries to parse TypeScript code as if it were regular JavaScript.
- This allows you to use typescript-eslint’s rules within your codebase.
- eslint:recommended is ESLint’s inbuilt «recommended» config — it turns on a small, sensible set of rules which lint for well-known best-practices.
- plugin:@typescript-eslint/recommended is our «recommended» config — it’s similar to eslint:recommended , except it turns on TypeScript-specific rules from our plugin.
Next Steps
We provide a plethora of powerful rules that utilize the power of TypeScript’s type information. Visit the next page for a setup guide.
If you’re having problems getting this working, please have a look at our Troubleshooting & FAQs.
Documentation Resources
- You can read more about configuring ESLint in their documentation on configuration.
- You can read more about the rules provided by ESLint in their documentation on their rules.
- You can read more about the rules provided by typescript-eslint in our rules documentation.
This package has been deprecated
Important: This repository is no longer maintained and typescript-eslint-parser will not receive any future updates. There is an actively maintained fork of this project available at https://typescript-eslint.io and published on npm as @typescript-eslint/parser .
- typescript-eslint-parser+ @typescript-eslint/parserAn ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
npm install --save-dev typescript-eslint-parserIn your ESLint configuration file, set the parser property:
"parser": "typescript-eslint-parser">There is sometimes an incorrect assumption that the parser itself is what does everything necessary to facilitate the use of ESLint with TypeScript. In actuality, it is the combination of the parser and one or more plugins which allow you to maximize your usage of ESLint with TypeScript.
For example, once this parser successfully produces an AST for the TypeScript source code, it might well contain some information which simply does not exist in a standard JavaScript context, such as the data for a TypeScript-specific construct, like an interface .
The core rules built into ESLint, such as indent have no knowledge of such constructs, so it is impossible to expect them to work out of the box with them.
Instead, you also need to make use of one more plugins which will add or extend rules with TypeScript-specific features.
By far the most common case will be installing the eslint-plugin-typescript plugin, but there are also other relevant options available such a eslint-plugin-tslint.
The following additional configuration options are available by specifying them in parserOptions in your ESLint configuration file.
- jsx — default false . Enable parsing JSX when true . More details can be found here.
- It’s false on *.ts files regardless of this option.
- It’s true on *.tsx files regardless of this option.
- Otherwise, it respects this option.
"parser": "typescript-eslint-parser","parserOptions":"jsx": true,"useJSXTextNode": true>>Supported TypeScript Version
We will always endeavor to support the latest stable version of TypeScript.
The version of TypeScript currently supported by this parser is ~3.2.1 . This is reflected in the devDependency requirement within the package.json file, and it is what the tests will be run against. We have an open peerDependency requirement in order to allow for experimentation on newer/beta versions of TypeScript.
If you use a non-supported version of TypeScript, the parser will log a warning to the console.
Please ensure that you are using a supported version before submitting any issues/bug reports.
We have a very flexible way of running integration tests which connects all of the moving parts of the usage of this parser in the ESLint ecosystem.
We run each test within its own docker container, and so each one has complete autonomy over what dependencies/plugins are installed and what versions are used. This also has the benefit of not bloating the package.json and node_modules of the parser project itself.
If you are going to submit an issue related to the usage of this parser with ESLint, please consider creating a failing integration test which clearly demonstrates the behavior. It’s honestly super quick!
You just need to duplicate one of the existing test sub-directories found in tests/integration/ , tweak the dependencies and ESLint config to match what you need, and add a new entry to the docker-compose.yml file which matches the format of the existing ones.
If you ever need to change what gets installed when the docker images are built by docker-compose, you will first need to kill the existing containers by running:
npm run kill-integration-test-containers- npm test — run all linting and tests
- npm run lint — run all linting
- npm run integration-tests — run only integration tests
TypeScript ESLint Parser is licensed under a permissive BSD 2-clause license.