Skip to content

Commit 8a72af9

Browse files
committed
Migrate React-Native template to flat config
1 parent 18fa07f commit 8a72af9

File tree

7 files changed

+104
-49
lines changed

7 files changed

+104
-49
lines changed

packages/react-native-template-redux-typescript/template/.eslintrc.json

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import js from "@eslint/js"
2+
import prettierConfig from "eslint-config-prettier/flat"
3+
import jestPlugin from "eslint-plugin-jest"
4+
import reactPlugin from "eslint-plugin-react"
5+
import reactHooksPlugin from "eslint-plugin-react-hooks"
6+
import globals from "globals"
7+
import { config, configs } from "typescript-eslint"
8+
9+
const eslintConfig = config(
10+
{
11+
name: "global-ignores",
12+
ignores: [
13+
"**/*.snap",
14+
"**/dist/",
15+
"**/.yalc/",
16+
"**/build/",
17+
"**/temp/",
18+
"**/.temp/",
19+
"**/.tmp/",
20+
"**/.yarn/",
21+
"**/coverage/",
22+
],
23+
},
24+
{
25+
name: `${js.meta.name}/recommended`,
26+
...js.configs.recommended,
27+
},
28+
configs.strictTypeChecked,
29+
configs.stylisticTypeChecked,
30+
{
31+
name: `${jestPlugin.meta.name}/recommended`,
32+
...jestPlugin.configs["flat/recommended"],
33+
},
34+
{
35+
name: "eslint-plugin-react/jsx-runtime",
36+
...reactPlugin.configs.flat["jsx-runtime"],
37+
},
38+
reactHooksPlugin.configs["recommended-latest"],
39+
{
40+
name: "main",
41+
linterOptions: {
42+
reportUnusedDisableDirectives: 2,
43+
},
44+
languageOptions: {
45+
ecmaVersion: 2020,
46+
globals: globals.node,
47+
parserOptions: {
48+
projectService: true,
49+
tsconfigRootDir: import.meta.dirname,
50+
},
51+
},
52+
rules: {
53+
"no-undef": [0],
54+
"no-restricted-imports": [
55+
2,
56+
{
57+
paths: [
58+
{
59+
name: "react-redux",
60+
importNames: ["useSelector", "useStore", "useDispatch"],
61+
message:
62+
"Please use pre-typed versions from `src/app/hooks.ts` instead.",
63+
},
64+
],
65+
},
66+
],
67+
"@typescript-eslint/consistent-type-definitions": [2, "type"],
68+
"@typescript-eslint/consistent-type-imports": [
69+
2,
70+
{
71+
prefer: "type-imports",
72+
fixStyle: "separate-type-imports",
73+
disallowTypeAnnotations: true,
74+
},
75+
],
76+
},
77+
},
78+
{
79+
name: "commonjs",
80+
files: ["metro.config.js"],
81+
languageOptions: {
82+
sourceType: "commonjs",
83+
},
84+
rules: {
85+
"@typescript-eslint/no-require-imports": [
86+
0,
87+
[{ allow: [], allowAsImport: false }],
88+
],
89+
},
90+
},
91+
92+
prettierConfig,
93+
)
94+
95+
export default eslintConfig

packages/react-native-template-redux-typescript/template/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@babel/core": "^7.26.9",
2525
"@babel/preset-env": "^7.26.9",
2626
"@babel/runtime": "^7.26.9",
27+
"@eslint/js": "^9.22.0",
2728
"@react-native-community/cli": "^17.0.0",
2829
"@react-native-community/cli-platform-android": "^17.0.0",
2930
"@react-native-community/cli-platform-ios": "^17.0.0",
@@ -38,9 +39,12 @@
3839
"@types/react": "^19.0.10",
3940
"@types/react-test-renderer": "^19.0.0",
4041
"babel-jest": "^29.7.0",
41-
"eslint": "^8.57.1",
42+
"eslint": "^9.22.0",
4243
"eslint-config-prettier": "^10.1.1",
4344
"eslint-plugin-jest": "^28.11.0",
45+
"eslint-plugin-react": "^7.37.4",
46+
"eslint-plugin-react-hooks": "^5.2.0",
47+
"globals": "^16.0.0",
4448
"jest": "^29.7.0",
4549
"prettier": "^3.5.3",
4650
"react-test-renderer": "^19.0.0",

packages/react-native-template-redux-typescript/template/src/app/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// usage of typed hooks throughout the application.
44
// We disable the ESLint rule here because this is the designated place
55
// for importing and re-exporting the typed versions of hooks.
6-
/* eslint-disable @typescript-eslint/no-restricted-imports */
6+
/* eslint-disable no-restricted-imports */
77
import { useEffect, useRef } from "react"
88
import { Animated, useWindowDimensions } from "react-native"
99
import { useDispatch, useSelector } from "react-redux"

packages/react-native-template-redux-typescript/template/src/constants/TypedColors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ type AllColors = {
1010
black: string
1111
}
1212

13-
export const TypedColors: AllColors = Colors
13+
export const TypedColors: AllColors = Colors satisfies AllColors as AllColors

packages/react-native-template-redux-typescript/template/src/features/counter/Counter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const Counter = (): JSX.Element => {
7575
style={styles.button}
7676
disabled={status !== "idle"}
7777
onPress={() => {
78-
dispatch(incrementAsync(incrementValue))
78+
void dispatch(incrementAsync(incrementValue))
7979
}}
8080
>
8181
<Text style={styles.buttonText}>Add Async</Text>

packages/react-native-template-redux-typescript/template/src/features/quotes/quotesApiSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const quotesApiSlice = createApi({
2525
// and the expected query argument. If there is no argument, use `void`
2626
// for the argument type instead.
2727
getQuotes: build.query<QuotesApiResponse, number>({
28-
query: (limit = 10) => `?limit=${limit}`,
28+
query: (limit = 10) => `?limit=${limit.toString()}`,
2929
// `providesTags` determines which 'tag' is attached to the
3030
// cached data returned by the query.
3131
providesTags: (_result, _error, id) => [{ type: "Quotes", id }],

0 commit comments

Comments
 (0)