Skip to content

Commit eaf45a3

Browse files
Enhance ESLint configuration and TypeScript support for react-on-rails packages
- Added specific ESLint configurations for the react-on-rails and react-on-rails-pro packages to handle import resolution issues in a monorepo setup. - Introduced new tsconfig.eslint.json files for both packages to extend the base TypeScript configuration and include relevant source and test files. - Updated the ESLint config to disable certain rules for the react-on-rails-pro package, ensuring compatibility with TypeScript's validation of imports. - Made minor adjustments to the RSCRoute component to remove unnecessary TypeScript directives, improving code clarity. These changes improve linting accuracy and TypeScript support across the project.
1 parent 9b34703 commit eaf45a3

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

eslint.config.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const compat = new FlatCompat({
1616
});
1717

1818
const config = tsEslint.config([
19+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
1920
includeIgnoreFile(path.resolve(__dirname, '.gitignore')),
2021
globalIgnores([
2122
// compiled code
@@ -156,6 +157,14 @@ const config = tsEslint.config([
156157
'import/extensions': ['error', 'ignorePackages'],
157158
},
158159
},
160+
{
161+
files: ['packages/react-on-rails-pro/**/*'],
162+
rules: {
163+
// Disable import/named for pro package - can't resolve monorepo workspace imports
164+
// TypeScript compiler validates these imports
165+
'import/named': 'off',
166+
},
167+
},
159168
{
160169
files: ['lib/generators/react_on_rails/templates/**/*'],
161170
rules: {
@@ -181,12 +190,7 @@ const config = tsEslint.config([
181190

182191
languageOptions: {
183192
parserOptions: {
184-
projectService: {
185-
allowDefaultProject: ['eslint.config.ts', 'knip.ts', 'packages/*/tests/*.test.{ts,tsx}'],
186-
// Needed because `import * as ... from` instead of `import ... from` doesn't work in this file
187-
// for some imports.
188-
defaultProject: 'tsconfig.eslint.json',
189-
},
193+
projectService: true,
190194
},
191195
},
192196

packages/react-on-rails-pro/src/RSCRoute.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* https://github.com/shakacode/react_on_rails/blob/master/REACT-ON-RAILS-PRO-LICENSE.md
1313
*/
1414

15+
/// <reference types="react/experimental" />
16+
1517
import * as React from 'react';
1618
import { useRSC } from './RSCProvider.tsx';
1719
import { ServerComponentFetchError } from './ServerComponentFetchError.ts';
@@ -73,8 +75,7 @@ export type RSCRouteProps = {
7375

7476
const PromiseWrapper = ({ promise }: { promise: Promise<React.ReactNode> }) => {
7577
// React.use is available in React 18.3+
76-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77-
return (React as any).use(promise);
78+
return React.use(promise);
7879
};
7980

8081
const RSCRoute = ({ componentName, componentProps }: RSCRouteProps): React.ReactNode => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*", "tests/**/*"]
4+
}

packages/react-on-rails/tests/serverRenderReactComponent.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('serverRenderReactComponent', () => {
2727
beforeEach(() => {
2828
ComponentRegistry.components().clear();
2929
// Setup globalThis.ReactOnRails for serverRenderReactComponent
30+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/unbound-method, @typescript-eslint/no-explicit-any
3031
globalThis.ReactOnRails = { getComponent: ComponentRegistry.get } as any;
3132
});
3233

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*", "tests/**/*"]
4+
}

0 commit comments

Comments
 (0)