Skip to content

Commit aad4df4

Browse files
committed
docs: update getting started and examples for 'ts-blank-eslint-parser'
1 parent 71abd78 commit aad4df4

File tree

4 files changed

+59
-19
lines changed

4 files changed

+59
-19
lines changed

examples/vite-react-dom-with-ts-blank-eslint-parser-app/eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import eslintJs from "@eslint/js";
33
import eslintReact from "@eslint-react/eslint-plugin";
44
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
55
import eslintPluginReactRefresh from "eslint-plugin-react-refresh";
6-
import tsEslintParser from "@typescript-eslint/parser";
76
import tsBlankEslintParser from "ts-blank-eslint-parser";
7+
import tseslint from "typescript-eslint";
88
import globals from "globals";
99

1010
import TSCONFIG from "./tsconfig.json" with { type: "json" };
@@ -70,7 +70,7 @@ export default [
7070
function getOptimalParser(project = "tsconfig.json") {
7171
return isFixable()
7272
? {
73-
parser: tsEslintParser,
73+
parser: tseslint.parser,
7474
parserOptions: {
7575
project,
7676
tsconfigRootDir: import.meta.dirname,

examples/vite-react-dom-with-ts-blank-eslint-parser-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@tsconfig/strictest": "^2.0.5",
2424
"@types/react": "^19.0.8",
2525
"@types/react-dom": "^19.0.3",
26-
"@typescript-eslint/parser": "^8.22.0",
2726
"@vitejs/plugin-react": "^4.3.4",
2827
"eslint": "^9.19.0",
2928
"eslint-plugin-react-hooks": "^5.1.0",
@@ -33,6 +32,7 @@
3332
"ts-blank-eslint-parser": "^0.3.1",
3433
"ts-blank-space": "^0.5.1",
3534
"typescript": "^5.7.3",
35+
"typescript-eslint": "^8.22.0",
3636
"vite": "^6.0.11"
3737
},
3838
"engines": {

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/content/docs/getting-started/typescript-with-alternative-parser.mdx

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,88 @@ title: TypeScript with alternative parser
33
description: Getting started with TypeScript + TS Blank ESLint Parser setup
44
---
55

6-
<Callout type="warn">The `ts-blank-eslint-parser` is a work in progress and not support rules that require type information or TypeScript syntax that need transformation like enums, namespaces, decorators. Use it with caution.</Callout>
6+
<Callout type="warn">
7+
The `ts-blank-eslint-parser` is a work in progress and comes with limitations:
78

8-
<Callout type="warn">When using this approach, the auto-fix may not work properly, it is recommended to use https://github.com/chiefmikey/eslint-plugin-disable-autofix to disable any problematic auto-fix without turning off the rule.</Callout>
9+
- No support for [TypeScript syntax](https://github.com/bloomberg/ts-blank-space/blob/main/docs/unsupported_syntax.md) that need transformation like enums, namespaces, decorators
10+
- No support for rules that require type information
11+
- No fixable support for types (the types will also be stripped out in the fix output)
12+
13+
Use it only if you are okay with the limitations.
14+
15+
</Callout>
916

1017
## Install
1118

1219
```sh copy title="Terminal"
1320
# npm
14-
npm install --save-dev eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin
21+
npm install --save-dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin
1522

1623
# pnpm
17-
pnpm add --save-dev eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin
24+
pnpm add --save-dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin
1825

1926
# yarn
20-
yarn add --dev eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin
27+
yarn add --dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parser @eslint-react/eslint-plugin
2128
```
2229

2330
## Setup
2431

2532
```js title="eslint.config.js"
33+
// @ts-check
2634
import eslintJs from "@eslint/js";
2735
import eslintReact from "@eslint-react/eslint-plugin";
2836
import tsBlankEslintParser from "ts-blank-eslint-parser";
37+
import tseslint from "typescript-eslint";
2938
import globals from "globals";
3039

40+
import TSCONFIG from "./tsconfig.json" with { type: "json" };
41+
import TSCONFIG_NODE from "./tsconfig.node.json" with { type: "json" };
42+
import { isInEditorEnv } from "@eslint-react/shared";
43+
44+
const GLOB_TS = ["**/*.ts", "**/*.tsx"];
45+
3146
export default [
47+
// base configuration for browser environment source files
3248
{
33-
files: ["**/*.ts", "**/*.tsx"],
34-
...eslintJs.configs.recommended,
49+
files: TSCONFIG.include,
3550
languageOptions: {
3651
globals: {
3752
...globals.browser,
3853
},
39-
parser: tsBlankEslintParser,
54+
...getOptimalParser(),
4055
},
41-
},
42-
{
43-
files: ["**/*.ts", "**/*.tsx"],
4456
rules: {
45-
// Put rules you want to override here
46-
"@eslint-react/prefer-shorthand-boolean": "warn",
57+
...eslintJs.configs.recommended.rules,
4758
},
4859
},
60+
// React configuration
61+
{
62+
files: TSCONFIG.include,
63+
...eslintReact.configs.recommended,
64+
},
4965
];
66+
67+
function getOptimalParser(project = "tsconfig.json") {
68+
return !isFixable()
69+
? {
70+
// fast but no fixable support for types
71+
parser: tsBlankEslintParser,
72+
}
73+
: {
74+
// slow but needed for fixable to work
75+
parser: tseslint.parser,
76+
parserOptions: {
77+
project,
78+
tsconfigRootDir: import.meta.dirname,
79+
},
80+
};
81+
}
82+
83+
function isFixable() {
84+
return isInEditorEnv() || hasFixFlag();
85+
}
86+
87+
function hasFixFlag() {
88+
return process.argv.includes("--fix");
89+
}
5090
```

0 commit comments

Comments
 (0)