|
| 1 | +--- |
| 2 | +title: TypeScript with alternative parser |
| 3 | +description: Getting started with TypeScript + TS Blank Space ESLint Parser setup |
| 4 | +--- |
| 5 | + |
| 6 | +## Install |
| 7 | + |
| 8 | +```sh copy title="Terminal" |
| 9 | +# npm |
| 10 | +npm install --save-dev eslint ts-blank-space-eslint-parser @eslint-react/eslint-plugin |
| 11 | + |
| 12 | +# pnpm |
| 13 | +pnpm add --save-dev eslint ts-blank-space-eslint-parser @eslint-react/eslint-plugin |
| 14 | + |
| 15 | +# yarn |
| 16 | +yarn add --dev eslint ts-blank-space-eslint-parser @eslint-react/eslint-plugin |
| 17 | +``` |
| 18 | + |
| 19 | +## Setup |
| 20 | + |
| 21 | +```js title="eslint.config.js" |
| 22 | + |
| 23 | +// @ts-check |
| 24 | +import eslintJs from "@eslint/js"; |
| 25 | +import eslintReact from "@eslint-react/eslint-plugin"; |
| 26 | +import tsBlankSpaceEslintParser from "ts-blank-space-eslint-parser"; |
| 27 | + |
| 28 | +export default tseslint.config({ |
| 29 | + files: ["**/*.ts", "**/*.tsx"], |
| 30 | + extends: [ |
| 31 | + eslintJs.configs.recommended, |
| 32 | + eslintReact.configs.recommended, |
| 33 | + ], |
| 34 | + languageOptions: { |
| 35 | + parser: tsBlankSpaceEslintParser, |
| 36 | + }, |
| 37 | +}); |
| 38 | +``` |
| 39 | + |
| 40 | +## Setup with Fallback Parsers |
| 41 | + |
| 42 | +```js title="eslint.config.js" |
| 43 | + |
| 44 | +// @ts-check |
| 45 | +import eslintJs from "@eslint/js"; |
| 46 | +import eslintReact from "@eslint-react/eslint-plugin"; |
| 47 | +import tsBlankSpaceEslintParser from "ts-blank-space-eslint-parser"; |
| 48 | +import tseslint from "typescript-eslint"; |
| 49 | + |
| 50 | +export default tseslint.config({ |
| 51 | + files: ["**/*.ts", "**/*.tsx"], |
| 52 | + extends: [ |
| 53 | + eslintJs.configs.recommended, |
| 54 | + eslintReact.configs.recommended, |
| 55 | + ], |
| 56 | + languageOptions: { |
| 57 | + parser: tsBlankSpaceEslintParser, |
| 58 | + parserOptions: { |
| 59 | + // Fallback to `@typescript-eslint/parser` when `ts-blank-space-eslint-parser` fails |
| 60 | + fallbackParsers: [ |
| 61 | + { |
| 62 | + parser: tseslint.parser, |
| 63 | + parserOptions: { |
| 64 | + projectService: true, |
| 65 | + }, |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + }, |
| 70 | +}); |
| 71 | +``` |
0 commit comments