Skip to content

Commit 6baeb9f

Browse files
upupmingcolinaaa
andauthored
feat(eslint): support eslint for ReactLynx (#1274)
<!-- Thank you for submitting a pull request! We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request. Upon submission, your pull request will be automatically assigned with reviewers. If you want to learn more about contributing to this project, please visit: https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md. --> ## Summary <!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? --> <!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. --> Support ESLint for ReactLynx. As `eslint-plugin-react-hooks` is the prerequisite eslint rule for [React Compiler](https://react.dev/learn/react-compiler#installing-eslint-plugin-react-compiler), we need to support eslint for ReactLynx before landing React Compiler. Related PR: #1269 ## Checklist <!--- Check and mark with an "x" --> - [x] Tests updated (or not required). - [x] Documentation updated (or not required). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added ESLint support for ReactLynx templates, including integration with React Hooks and React Refresh linting rules. * Enabled linting for example TypeScript and TSX files. * Implemented ESLint template mapping for React JavaScript and TypeScript projects. * **Bug Fixes** * Updated callback prop from `onMounted` to `onRender` in relevant components and tests for improved consistency. * **Style** * Refined JSX syntax by converting empty elements to self-closing tags. * **Chores** * Updated test workflows to include ESLint checks. * Added new ESLint plugins to development dependencies. * Added a changeset documenting ESLint support. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Yiming Li <yimingli.cs@gmail.com> Co-authored-by: Qingyu Wang <40660121+colinaaa@users.noreply.github.com>
1 parent bc1c452 commit 6baeb9f

File tree

21 files changed

+132
-50
lines changed

21 files changed

+132
-50
lines changed

.changeset/floppy-singers-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-rspeedy": patch
3+
---
4+
5+
Support ESLint for ReactLynx templates

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,18 @@ jobs:
146146
node packages/tools/canary-release/snapshot.js
147147
pnpm --recursive publish --no-git-checks --access public --registry=http://localhost:4873
148148
cd `mktemp -d`
149-
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react --dir create-rspeedy-regression
149+
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react --dir create-rspeedy-regression --tools eslint
150150
cd create-rspeedy-regression
151151
pnpm install --registry=http://localhost:4873
152152
pnpm run build
153153
pnpm run build --mode development
154-
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react-vitest-rltl --dir create-rspeedy-regression-vitest-rltl
154+
pnpm run lint
155+
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react-vitest-rltl --dir create-rspeedy-regression-vitest-rltl --tools eslint
155156
cd create-rspeedy-regression-vitest-rltl
156157
pnpm install --registry=http://localhost:4873
157158
pnpm run build
158159
pnpm run build --mode development
160+
pnpm run lint
159161
pnpm run test
160162
test-react:
161163
needs: build

eslint.config.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import * as regexpPlugin from 'eslint-plugin-regexp';
1212
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
1313
import globals from 'globals';
1414
import tseslint from 'typescript-eslint';
15+
import reactHooks from 'eslint-plugin-react-hooks';
16+
import reactRefresh from 'eslint-plugin-react-refresh';
1517

1618
export default tseslint.config(
1719
// Global ignores
@@ -67,7 +69,6 @@ export default tseslint.config(
6769

6870
// TODO: enable eslint for react
6971
// react
70-
'examples/**',
7172
'packages/react/types/**',
7273
'packages/react/runtime/__test__/**',
7374
'packages/react/runtime/jsx-dev-runtime/**',
@@ -383,4 +384,31 @@ export default tseslint.config(
383384
'@typescript-eslint/require-await': 'off',
384385
},
385386
},
387+
// React-related
388+
{
389+
files: [
390+
'examples/**/*.{jsx,tsx}',
391+
],
392+
extends: [
393+
reactHooks.configs['recommended-latest'],
394+
reactRefresh.configs.vite,
395+
],
396+
},
397+
{
398+
files: [
399+
'examples/**',
400+
],
401+
settings: {
402+
'import/resolver': {
403+
typescript: {
404+
project: 'examples/**/tsconfig.json',
405+
noWarnOnMultipleProjects: true,
406+
},
407+
},
408+
},
409+
rules: {
410+
// TODO: enable header for examples
411+
'headers/header-format': 'off',
412+
},
413+
},
386414
);

examples/react/lynx.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { defineConfig } from '@lynx-js/rspeedy';
21
import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin';
32
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
3+
import { defineConfig } from '@lynx-js/rspeedy';
44

55
const enableBundleAnalysis = !!process.env['RSPEEDY_BUNDLE_ANALYSIS'];
66

examples/react/test/jsx-runtime.test-d.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { assertType, describe, expectTypeOf, test } from 'vitest';
55

66
import {
77
Component,
8-
forwardRef,
98
Fragment,
10-
memo,
119
Suspense,
10+
forwardRef,
11+
memo,
1212
useMainThreadRef,
1313
useRef,
1414
} from '@lynx-js/react';

examples/react/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"checkJs": true,
1010
"isolatedDeclarations": false,
1111
},
12-
"include": ["src", "lynx.config.js", "test"],
12+
"include": ["src", "lynx.config.js", "test", "vitest.config.ts"],
1313
"references": [
1414
{ "path": "../../packages/react/tsconfig.json" },
1515
{ "path": "../../packages/rspeedy/core/tsconfig.build.json" },

examples/tailwindcss/lynx.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { defineConfig } from '@lynx-js/rspeedy';
1+
import { pluginTailwindCSS } from 'rsbuild-plugin-tailwindcss';
2+
23
import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin';
34
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
4-
import { pluginTailwindCSS } from 'rsbuild-plugin-tailwindcss';
5+
import { defineConfig } from '@lynx-js/rspeedy';
56

67
export default defineConfig({
78
plugins: [

examples/tailwindcss/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from '@lynx-js/react';
2+
23
import { cn } from './utils.js';
34
import './App.css';
45

examples/tailwindcss/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { root } from '@lynx-js/react';
2+
23
import { App } from './App.js';
34

45
root.render(

examples/tailwindcss/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { clsx, type ClassValue } from 'clsx';
1+
import { clsx } from 'clsx';
2+
import type { ClassValue } from 'clsx';
23
import { twMerge } from 'tailwind-merge';
4+
35
export function cn(...inputs: ClassValue[]) {
46
return twMerge(clsx(inputs));
57
}

0 commit comments

Comments
 (0)