Skip to content

Commit 76c6726

Browse files
committed
docs: update examples
1 parent 2c77165 commit 76c6726

File tree

4 files changed

+41
-62
lines changed

4 files changed

+41
-62
lines changed

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ import TSCONFIG from "./tsconfig.json" with { type: "json" };
1111
import TSCONFIG_NODE from "./tsconfig.node.json" with { type: "json" };
1212
import { isInEditorEnv } from "@eslint-react/shared";
1313

14-
const GLOB_TS = ["**/*.ts", "**/*.tsx"];
14+
function getOptimalParserConfig(project = "tsconfig.json") {
15+
switch (true) {
16+
case isInEditorEnv():
17+
case process.argv.includes("--fix"):
18+
return {
19+
parser: tseslint.parser,
20+
parserOptions: {
21+
project,
22+
tsconfigRootDir: import.meta.dirname,
23+
},
24+
};
25+
}
26+
return { parser: tsBlankEslintParser };
27+
}
1528

1629
export default [
1730
// base configuration for browser environment source files
@@ -21,7 +34,7 @@ export default [
2134
globals: {
2235
...globals.browser,
2336
},
24-
...getOptimalParser(),
37+
...getOptimalParserConfig(),
2538
},
2639
rules: {
2740
...eslintJs.configs.recommended.rules,
@@ -35,7 +48,7 @@ export default [
3548
globals: {
3649
...globals.node,
3750
},
38-
...getOptimalParser("tsconfig.node.json"),
51+
...getOptimalParserConfig("tsconfig.node.json"),
3952
},
4053
rules: {
4154
...eslintJs.configs.recommended.rules,
@@ -66,25 +79,3 @@ export default [
6679
},
6780
},
6881
];
69-
70-
function getOptimalParser(project = "tsconfig.json") {
71-
return isFixable()
72-
? {
73-
parser: tseslint.parser,
74-
parserOptions: {
75-
project,
76-
tsconfigRootDir: import.meta.dirname,
77-
},
78-
}
79-
: {
80-
parser: tsBlankEslintParser,
81-
};
82-
}
83-
84-
function isFixable() {
85-
return isInEditorEnv() || hasFixFlag();
86-
}
87-
88-
function hasFixFlag() {
89-
return process.argv.includes("--fix");
90-
}

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
@@ -29,7 +29,7 @@
2929
"eslint-plugin-react-refresh": "^0.4.18",
3030
"globals": "^15.14.0",
3131
"meriyah": "^6.0.5",
32-
"ts-blank-eslint-parser": "^0.3.1",
32+
"ts-blank-eslint-parser": "^0.3.2",
3333
"ts-blank-space": "^0.5.1",
3434
"typescript": "^5.7.3",
3535
"typescript-eslint": "^8.22.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 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: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,58 +33,46 @@ yarn add --dev eslint typescript-eslint @eslint/js globals ts-blank-eslint-parse
3333
// @ts-check
3434
import eslintJs from "@eslint/js";
3535
import eslintReact from "@eslint-react/eslint-plugin";
36+
import { isInEditorEnv } from "@eslint-react/shared";
3637
import tsBlankEslintParser from "ts-blank-eslint-parser";
3738
import tseslint from "typescript-eslint";
3839
import globals from "globals";
3940

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-
4441
const GLOB_TS = ["**/*.ts", "**/*.tsx"];
4542

43+
function getOptimalParserConfig(project = "tsconfig.json") {
44+
switch (true) {
45+
case isInEditorEnv():
46+
case process.argv.includes("--fix"):
47+
return {
48+
parser: tseslint.parser,
49+
parserOptions: {
50+
project,
51+
tsconfigRootDir: import.meta.dirname,
52+
},
53+
};
54+
}
55+
return { parser: tsBlankEslintParser };
56+
}
57+
4658
export default [
4759
// base configuration for browser environment source files
4860
{
49-
files: TSCONFIG.include,
61+
files: GLOB_TS,
5062
languageOptions: {
5163
globals: {
5264
...globals.browser,
5365
},
54-
...getOptimalParser(),
66+
...getOptimalParserConfig(),
5567
},
5668
rules: {
5769
...eslintJs.configs.recommended.rules,
5870
},
5971
},
6072
// React configuration
6173
{
62-
files: TSCONFIG.include,
74+
files: GLOB_TS,
6375
...eslintReact.configs.recommended,
6476
},
6577
];
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-
}
9078
```

0 commit comments

Comments
 (0)