Skip to content

Commit 1c34567

Browse files
authored
feat(react): add eslint + typescript configuration (#2)
1 parent c9ccd71 commit 1c34567

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/react.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import js from "@eslint/js"
2+
import eslintConfigPrettier from "eslint-config-prettier"
3+
import tseslint from "typescript-eslint"
4+
import pluginReactHooks from "eslint-plugin-react-hooks"
5+
import pluginReact from "eslint-plugin-react"
6+
import globals from "globals"
7+
import { config as baseConfig } from "./base.js"
8+
9+
/**
10+
* Shared eslint configuration for react-based libraries and applications
11+
*
12+
* @type {import("eslint").Linter.Config[]}
13+
*/
14+
export const config = [
15+
// Inherit shared base configuration
16+
...baseConfig,
17+
18+
// Core JavaScript linting rules from ESLint
19+
js.configs.recommended,
20+
21+
// Disables ESLint rules that conflict with Prettier formatting
22+
eslintConfigPrettier,
23+
24+
// Recommended rules for TypeScript projects
25+
...tseslint.configs.recommended,
26+
27+
// Recommended rules for React projects using the flat config API
28+
pluginReact.configs.flat.recommended,
29+
30+
{
31+
// Extend language options to include browser and service worker globals
32+
languageOptions: {
33+
...pluginReact.configs.flat.recommended.languageOptions,
34+
globals: { ...globals.serviceworker, ...globals.browser },
35+
},
36+
},
37+
{
38+
// React Hooks plugin configuration
39+
plugins : { "react-hooks": pluginReactHooks },
40+
settings : {
41+
// Automatically detect the installed React version
42+
react: { version: "detect" },
43+
},
44+
rules : {
45+
// Include recommended rules for React Hooks
46+
...pluginReactHooks.configs.recommended.rules,
47+
48+
// Disable rule requiring React to be in scope for JSX
49+
// Not needed with the new JSX transform (React 17+)
50+
"react/react-in-jsx-scope": "off",
51+
},
52+
},
53+
]

src/react.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema" : "https://json.schemastore.org/tsconfig",
3+
"extends" : "./base.json",
4+
"compilerOptions" : {
5+
"jsx": "react-jsx"
6+
}
7+
}

0 commit comments

Comments
 (0)