Skip to content

Commit f6aa792

Browse files
committed
Migrate root level ESLint config to flat config
1 parent 3816ae8 commit f6aa792

File tree

6 files changed

+142
-26
lines changed

6 files changed

+142
-26
lines changed

.eslintrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

eslint.config.mts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import js from "@eslint/js"
2+
import prettierConfig from "eslint-config-prettier/flat"
3+
import type { ConfigArray } from "typescript-eslint"
4+
import { config, configs } from "typescript-eslint"
5+
6+
const eslintConfig: ConfigArray = config(
7+
{
8+
name: "global-ignores",
9+
ignores: [
10+
"**/*.snap",
11+
"**/dist/",
12+
"**/.yalc/",
13+
"**/build/",
14+
"**/temp/",
15+
"**/.temp/",
16+
"**/.tmp/",
17+
"**/.yarn/",
18+
"**/coverage/",
19+
"packages/rtk-app-structure-example",
20+
"packages/vite-template-redux",
21+
"packages/react-native-template-redux-typescript/template",
22+
"packages/expo-template-redux-typescript",
23+
"packages/cra-template-redux/template",
24+
"packages/cra-template-redux-typescript/template",
25+
],
26+
},
27+
{
28+
name: `${js.meta.name}/recommended`,
29+
...js.configs.recommended,
30+
},
31+
configs.strictTypeChecked,
32+
configs.stylisticTypeChecked,
33+
{
34+
name: "main",
35+
linterOptions: {
36+
reportUnusedDisableDirectives: 2,
37+
},
38+
languageOptions: {
39+
parserOptions: {
40+
projectService: true,
41+
tsconfigRootDir: import.meta.dirname,
42+
},
43+
},
44+
rules: {
45+
"no-undef": [0],
46+
"@typescript-eslint/consistent-type-definitions": [2, "type"],
47+
"@typescript-eslint/consistent-type-imports": [
48+
2,
49+
{
50+
prefer: "type-imports",
51+
fixStyle: "separate-type-imports",
52+
disallowTypeAnnotations: true,
53+
},
54+
],
55+
},
56+
},
57+
58+
prettierConfig,
59+
)
60+
61+
export default eslintConfig

package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@
99
},
1010
"repository": {
1111
"type": "git",
12-
"url": "git+https://github.com/reduxjs/redux-templates.git"
12+
"url": "git+https://github.com/reduxjs/redux-templates.git",
13+
"directory": "."
1314
},
1415
"workspaces": [
1516
"packages/*"
1617
],
1718
"scripts": {
18-
"format": "prettier --write . --cache --cache-strategy content",
19-
"format:check": "prettier --check .",
20-
"lint": "eslint . --cache --cache-strategy content",
21-
"lint:fix": "eslint . --fix",
22-
"build": "yarn workspaces foreach -A run build"
19+
"format": "prettier --config=$INIT_CWD/prettier.config.mjs --write $INIT_CWD",
20+
"format-check": "prettier --config=$INIT_CWD/prettier.config.mjs --check $INIT_CWD",
21+
"lint": "eslint --config=$INIT_CWD/eslint.config.mts $INIT_CWD",
22+
"lint-fix": "eslint --config=$INIT_CWD/eslint.config.mts $INIT_CWD --fix",
23+
"type-check": "tsc -p $INIT_CWD/tsconfig.json --noEmit"
2324
},
2425
"devDependencies": {
26+
"@eslint/js": "^9.22.0",
2527
"@types/node": "^22.13.10",
2628
"eslint": "^9.22.0",
29+
"eslint-config-prettier": "^10.1.1",
30+
"jiti": "^2.4.2",
2731
"prettier": "^3.5.3",
2832
"rimraf": "^6.0.1",
2933
"tsx": "^4.19.3",
30-
"typescript": "^5.8.2"
34+
"typescript": "^5.8.2",
35+
"typescript-eslint": "^8.26.1"
3136
},
3237
"packageManager": "[email protected]"
3338
}

scripts/mockTemplates.mts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env -vS node --import=tsx
22

3+
import type { ExecFileOptionsWithStringEncoding } from "node:child_process"
34
import * as childProcess from "node:child_process"
45
import * as fs from "node:fs/promises"
56
import * as os from "node:os"
@@ -15,7 +16,7 @@ const testDirectory = path.join(homeOrTempDir, "test-redux-templates")
1516
/**
1617
* Retrieves a map of Yarn workspaces and their corresponding locations.
1718
*
18-
* @returns A promise that resolves to a map of workspace names and their locations.
19+
* @returns A {@linkcode Promise | promise} that resolves to a map of workspace names and their locations.
1920
* @throws An error If there is an error while listing Yarn workspaces.
2021
*/
2122
const listYarnWorkspaces = async () => {
@@ -34,16 +35,17 @@ const listYarnWorkspaces = async () => {
3435
JSON.parse(line)
3536
return true
3637
} catch (error) {
38+
console.error(error)
3739
return false
3840
}
3941
})
40-
.map(line => JSON.parse(line))
42+
.map(line => JSON.parse(line) as { location: string; name: string })
4143
.filter(({ location }) => location !== ".")
4244

4345
// Extract workspace names or any other property you need
4446
const workspaceNames = new Map(
4547
workspaces.map(workspace => [
46-
workspace.name as string,
48+
workspace.name,
4749
path.join(import.meta.dirname, "..", workspace.location),
4850
]),
4951
)
@@ -85,13 +87,14 @@ async function constructGitHubUrl(): Promise<{
8587

8688
const gitHubUrl = await constructGitHubUrl()
8789

88-
type AllTemplates = {
89-
[key: string]: {
90+
type AllTemplates = Record<
91+
string,
92+
{
9093
command: string
9194
args: string[]
92-
options?: childProcess.ExecFileOptionsWithStringEncoding
95+
options?: Partial<ExecFileOptionsWithStringEncoding>
9396
}
94-
}
97+
>
9598

9699
const allTemplates: AllTemplates = {
97100
"cra-template-redux": {
@@ -101,7 +104,7 @@ const allTemplates: AllTemplates = {
101104
"create-react-app@latest",
102105
"example",
103106
"--template",
104-
`file:${workspaces.get("cra-template-redux")}`,
107+
`file:${workspaces.get("cra-template-redux") ?? ""}`,
105108
],
106109
},
107110
"cra-template-redux-typescript": {
@@ -111,7 +114,7 @@ const allTemplates: AllTemplates = {
111114
"create-react-app@latest",
112115
"example",
113116
"--template",
114-
`file:${workspaces.get("cra-template-redux-typescript")}`,
117+
`file:${workspaces.get("cra-template-redux-typescript") ?? ""}`,
115118
],
116119
},
117120
"expo-template-redux-typescript": {
@@ -121,7 +124,7 @@ const allTemplates: AllTemplates = {
121124
"create-expo@latest",
122125
"example",
123126
"--template",
124-
`file:${workspaces.get("expo-template-redux-typescript")}`,
127+
`file:${workspaces.get("expo-template-redux-typescript") ?? ""}`,
125128
],
126129
},
127130
"react-native-template-redux-typescript": {
@@ -132,7 +135,7 @@ const allTemplates: AllTemplates = {
132135
"init",
133136
"app",
134137
"--template",
135-
`file:${workspaces.get("react-native-template-redux-typescript")}`,
138+
`file:${workspaces.get("react-native-template-redux-typescript") ?? ""}`,
136139
"--pm=npm",
137140
"--directory",
138141
"example",
@@ -163,7 +166,7 @@ const createTempDirectories = async (templates: string[]) => {
163166
return Object.fromEntries(
164167
await Promise.all(
165168
templates.map(async template => {
166-
const tempDirectory = path.resolve(testDirectory, template)
169+
const tempDirectory = path.join(testDirectory, template)
167170

168171
console.log(
169172
`Creating temporary directory for ${template} at ${tempDirectory}`,

tsconfig.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"allowSyntheticDefaultImports": true,
5+
"checkJs": true,
6+
"declaration": true,
7+
"esModuleInterop": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"isolatedModules": true,
10+
"jsx": "react-jsx",
11+
"lib": ["DOM", "ESNext"],
12+
"module": "ESNext",
13+
"moduleResolution": "bundler",
14+
"noEmit": true,
15+
"noErrorTruncation": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"noImplicitOverride": true,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": false,
20+
"noUnusedParameters": false,
21+
"outDir": "./dist",
22+
"resolveJsonModule": true,
23+
"rootDir": "./",
24+
"skipLibCheck": true,
25+
"sourceMap": true,
26+
"strict": true,
27+
"target": "ESNext",
28+
"types": ["vitest/globals", "vitest/importMeta"],
29+
"useDefineForClassFields": true,
30+
"useUnknownInCatchVariables": true
31+
},
32+
"exclude": [
33+
"dist",
34+
"packages/cra-template-redux/template",
35+
"packages/cra-template-redux-typescript/template",
36+
"packages/expo-template-redux-typescript",
37+
"packages/react-native-template-redux-typescript/template",
38+
"packages/rtk-app-structure-example",
39+
"packages/vite-template-redux"
40+
]
41+
}

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13140,6 +13140,15 @@ __metadata:
1314013140
languageName: node
1314113141
linkType: hard
1314213142

13143+
"jiti@npm:^2.4.2":
13144+
version: 2.4.2
13145+
resolution: "jiti@npm:2.4.2"
13146+
bin:
13147+
jiti: lib/jiti-cli.mjs
13148+
checksum: 10/e2b07eb2e3fbb245e29ad288dddecab31804967fc84d5e01d39858997d2743b5e248946defcecf99272275a00284ecaf7ec88b8c841331324f0c946d8274414b
13149+
languageName: node
13150+
linkType: hard
13151+
1314313152
"joi@npm:^17.2.1":
1314413153
version: 17.13.3
1314513154
resolution: "joi@npm:17.13.3"
@@ -17141,12 +17150,16 @@ __metadata:
1714117150
version: 0.0.0-use.local
1714217151
resolution: "redux-templates@workspace:."
1714317152
dependencies:
17153+
"@eslint/js": "npm:^9.22.0"
1714417154
"@types/node": "npm:^22.13.10"
1714517155
eslint: "npm:^9.22.0"
17156+
eslint-config-prettier: "npm:^10.1.1"
17157+
jiti: "npm:^2.4.2"
1714617158
prettier: "npm:^3.5.3"
1714717159
rimraf: "npm:^6.0.1"
1714817160
tsx: "npm:^4.19.3"
1714917161
typescript: "npm:^5.8.2"
17162+
typescript-eslint: "npm:^8.26.1"
1715017163
languageName: unknown
1715117164
linkType: soft
1715217165

0 commit comments

Comments
 (0)