Skip to content

Commit 2c9ad13

Browse files
committed
refactor(examples): use 'jsconfig.json' as the source of globs in eslint configs
1 parent 0119497 commit 2c9ad13

File tree

7 files changed

+109
-33
lines changed

7 files changed

+109
-33
lines changed

examples/next-app/app/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default function Home() {
8383
className="bg-white text-xs rounded-3xl flex items-center h-8 px-2 relative select-none"
8484
>
8585
<button
86+
type="button"
8687
aria-label="Customise options"
8788
className="h-8 w-8 inline-flex items-center justify-center shadow-lg"
8889
>

examples/vite-react-dom-js-app/eslint.config.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import reactHooks from "eslint-plugin-react-hooks";
44
import reactRefresh from "eslint-plugin-react-refresh";
55
import globals from "globals";
66

7-
const GLOB_JS = ["*.{js,jsx,cjs,mjs}", "**/*.{js,jsx,cjs,mjs}"];
8-
const GLOB_SRC = GLOB_JS.map((pattern) => `src/${pattern}`);
7+
import JSCONFIG from "./jsconfig.json" with { type: "json" };
8+
import JSCONFIG_NODE from "./jsconfig.node.json" with { type: "json" };
99

1010
export default [
11-
js.configs.recommended,
1211
{
13-
files: GLOB_JS,
12+
files: JSCONFIG.include,
1413
languageOptions: {
1514
globals: {
1615
...globals.browser,
@@ -23,18 +22,18 @@ export default [
2322
},
2423
},
2524
{
26-
files: GLOB_SRC,
25+
files: JSCONFIG.include,
2726
...react.configs.recommended,
2827
},
2928
{
30-
files: GLOB_SRC,
29+
files: JSCONFIG.include,
3130
plugins: {
3231
"react-hooks": reactHooks,
3332
},
3433
rules: reactHooks.configs.recommended.rules,
3534
},
3635
{
37-
files: GLOB_SRC,
36+
files: JSCONFIG.include,
3837
plugins: {
3938
"react-refresh": reactRefresh,
4039
},
@@ -43,11 +42,16 @@ export default [
4342
},
4443
},
4544
{
46-
ignores: [
47-
"node_modules",
48-
"dist",
49-
"eslint.config.js",
50-
"eslint.config.d.ts",
51-
],
45+
files: JSCONFIG_NODE.include,
46+
ignores: JSCONFIG_NODE.exclude,
47+
languageOptions: {
48+
globals: {
49+
...globals.node,
50+
},
51+
},
52+
rules: {
53+
...js.configs.recommended.rules,
54+
"no-console": "off",
55+
},
5256
},
5357
];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2021",
4+
"module": "ESNext",
5+
"moduleDetection": "force",
6+
"moduleResolution": "bundler",
7+
"jsx": "react-jsx",
8+
"lib": [
9+
"ES2021",
10+
"DOM",
11+
"DOM.Iterable"
12+
]
13+
},
14+
"include": [
15+
"src/**/*.js",
16+
"src/**/*.jsx"
17+
]
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"module": "ESNext",
4+
"moduleDetection": "force",
5+
"moduleResolution": "bundler"
6+
},
7+
"include": [
8+
"*.js",
9+
"*.cjs",
10+
"*.mjs"
11+
],
12+
"exclude": [
13+
"node_modules",
14+
"dist",
15+
"src",
16+
"benchmark"
17+
]
18+
}
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
11
import js from "@eslint/js";
2-
import parser from "@babel/eslint-parser";
32
import react from "@eslint-react/eslint-plugin";
43
import reactHooks from "eslint-plugin-react-hooks";
54
import reactRefresh from "eslint-plugin-react-refresh";
65
import globals from "globals";
76

8-
const GLOB_JS = ["*.{js,jsx,cjs,mjs}", "**/*.{js,jsx,cjs,mjs}"];
9-
const GLOB_SRC = GLOB_JS.map((pattern) => `src/${pattern}`);
7+
import JSCONFIG from "./jsconfig.json" with { type: "json" };
8+
import JSCONFIG_NODE from "./jsconfig.node.json" with { type: "json" };
109

1110
export default [
12-
js.configs.recommended,
1311
{
14-
files: GLOB_JS,
12+
files: JSCONFIG.include,
1513
languageOptions: {
1614
globals: {
1715
...globals.browser,
1816
},
19-
parser,
2017
parserOptions: {
21-
requireConfigFile: false,
22-
babelOptions: {
23-
babelrc: false,
24-
configFile: false,
25-
presets: ["@babel/preset-env", "@babel/preset-react"],
18+
ecmaFeatures: {
19+
jsx: true,
2620
},
2721
},
2822
},
2923
},
3024
{
31-
files: GLOB_SRC,
25+
files: JSCONFIG.include,
3226
...react.configs.recommended,
3327
},
3428
{
35-
files: GLOB_SRC,
29+
files: JSCONFIG.include,
3630
plugins: {
3731
"react-hooks": reactHooks,
3832
},
3933
rules: reactHooks.configs.recommended.rules,
4034
},
4135
{
42-
files: GLOB_SRC,
36+
files: JSCONFIG.include,
4337
plugins: {
4438
"react-refresh": reactRefresh,
4539
},
@@ -48,11 +42,16 @@ export default [
4842
},
4943
},
5044
{
51-
ignores: [
52-
"node_modules",
53-
"dist",
54-
"eslint.config.js",
55-
"eslint.config.d.ts",
56-
],
45+
files: JSCONFIG_NODE.include,
46+
ignores: JSCONFIG_NODE.exclude,
47+
languageOptions: {
48+
globals: {
49+
...globals.node,
50+
},
51+
},
52+
rules: {
53+
...js.configs.recommended.rules,
54+
"no-console": "off",
55+
},
5756
},
5857
];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2021",
4+
"module": "ESNext",
5+
"moduleDetection": "force",
6+
"moduleResolution": "bundler",
7+
"jsx": "react-jsx",
8+
"lib": [
9+
"ES2021",
10+
"DOM",
11+
"DOM.Iterable"
12+
]
13+
},
14+
"include": [
15+
"src/**/*.js",
16+
"src/**/*.jsx"
17+
]
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"module": "ESNext",
4+
"moduleDetection": "force",
5+
"moduleResolution": "bundler"
6+
},
7+
"include": [
8+
"*.js",
9+
"*.cjs",
10+
"*.mjs"
11+
],
12+
"exclude": [
13+
"node_modules",
14+
"dist",
15+
"src",
16+
"benchmark"
17+
]
18+
}

0 commit comments

Comments
 (0)