Skip to content

Commit e0fab93

Browse files
committed
Use strict TypeScript-ESLint config
1 parent c9319ca commit e0fab93

File tree

9 files changed

+29
-16
lines changed

9 files changed

+29
-16
lines changed

eslint.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const config = tsEslint.config([
140140
{
141141
files: ['**/*.ts', '**/*.tsx'],
142142

143-
extends: tsEslint.configs.recommendedTypeChecked,
143+
extends: tsEslint.configs.strictTypeChecked,
144144

145145
languageOptions: {
146146
parserOptions: {
@@ -156,6 +156,12 @@ const config = tsEslint.config([
156156
rules: {
157157
'@typescript-eslint/no-namespace': 'off',
158158
'@typescript-eslint/no-shadow': 'error',
159+
'@typescript-eslint/no-confusing-void-expression': [
160+
'error',
161+
{
162+
ignoreArrowShorthand: true,
163+
},
164+
],
159165
// Too many false positives
160166
'@typescript-eslint/no-unnecessary-condition': 'off',
161167
'@typescript-eslint/no-unused-vars': [

node_package/src/ClientSideRenderer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-classes-per-file */
2-
/* eslint-disable react/no-deprecated -- while we need to support React 16 */
2+
/* eslint-disable react/no-deprecated,@typescript-eslint/no-deprecated -- while we need to support React 16 */
33

44
import * as ReactDOM from 'react-dom';
55
import type { ReactElement } from 'react';
@@ -163,8 +163,8 @@ You should return a React.Component always for the client side entry point.`);
163163
}
164164

165165
waitUntilRendered(): Promise<void> {
166-
if (this.state === 'rendering') {
167-
return this.renderPromise!;
166+
if (this.state === 'rendering' && this.renderPromise) {
167+
return this.renderPromise;
168168
}
169169
return Promise.resolve();
170170
}
@@ -207,8 +207,8 @@ class StoreRenderer {
207207
}
208208

209209
waitUntilHydrated(): Promise<void> {
210-
if (this.state === 'hydrating') {
211-
return this.hydratePromise!;
210+
if (this.state === 'hydrating' && this.hydratePromise) {
211+
return this.hydratePromise;
212212
}
213213
return Promise.resolve();
214214
}

node_package/src/ReactOnRails.client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,10 @@ ctx.ReactOnRails = {
203203

204204
/**
205205
* Allows saving the store populated by Rails form props. Used internally by ReactOnRails.
206-
* @param name
207206
* @returns Redux Store, possibly hydrated
208207
*/
209208
setStore(name: string, store: Store): void {
210-
return StoreRegistry.setStore(name, store);
209+
StoreRegistry.setStore(name, store);
211210
},
212211

213212
/**

node_package/src/ReactOnRailsRSC.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const streamRenderRSCComponent = (reactElement: ReactElement, options: RSCRender
4646
});
4747
pipeToTransform(rscStream);
4848
})
49-
.catch((e) => {
49+
.catch((e: unknown) => {
5050
const error = convertToError(e);
5151
renderState.hasErrors = true;
5252
renderState.error = error;

node_package/src/clientStartup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { debugTurbolinks } from './turbolinksUtils';
1111

1212
export async function reactOnRailsPageLoaded() {
1313
debugTurbolinks('reactOnRailsPageLoaded');
14-
await Promise.all([hydrateAllStores(), renderOrHydrateAllComponents()]);
14+
const promise = hydrateAllStores();
15+
renderOrHydrateAllComponents();
16+
await promise;
1517
}
1618

1719
function reactOnRailsPageUnloaded(): void {

node_package/src/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type Context = Window | typeof globalThis;
1818
/**
1919
* Get the context, be it window or global
2020
*/
21+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
2122
export default function context(this: void): Context | void {
2223
return (typeof window !== 'undefined' && window) || (typeof global !== 'undefined' && global) || this;
2324
}

node_package/src/loadReactClientManifest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ export default async function loadReactClientManifest(reactClientManifestFileNam
99
// Renderer copies assets to the same place as the server-bundle.js and rsc-bundle.js.
1010
// Thus, the __dirname of this code is where we can find the manifest file.
1111
const manifestPath = path.resolve(__dirname, reactClientManifestFileName);
12-
if (!loadedReactClientManifests.has(manifestPath)) {
12+
const loadedReactClientManifest = loadedReactClientManifests.get(manifestPath);
13+
if (!loadedReactClientManifest) {
1314
// TODO: convert to async
1415
try {
1516
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')) as ClientManifest;
1617
loadedReactClientManifests.set(manifestPath, manifest);
18+
return manifest;
1719
} catch (error) {
1820
throw new Error(`Failed to load React client manifest from ${manifestPath}: ${error}`);
1921
}
2022
}
2123

22-
return loadedReactClientManifests.get(manifestPath)!;
24+
return loadedReactClientManifest;
2325
}

node_package/src/reactHydrateOrRender.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ if (supportsRootApi) {
2222
}
2323
}
2424

25-
/* eslint-disable react/no-deprecated -- while we need to support React 16 */
25+
/* eslint-disable react/no-deprecated,@typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion --
26+
* while we need to support React 16
27+
*/
2628
const reactHydrate: HydrateOrRenderType = supportsRootApi
27-
? reactDomClient.hydrateRoot
29+
? reactDomClient!.hydrateRoot
2830
: (domNode, reactElement) => ReactDOM.hydrate(reactElement, domNode);
2931

3032
function reactRender(domNode: Element, reactElement: ReactElement): RenderReturnType {
3133
if (supportsRootApi) {
32-
const root = reactDomClient.createRoot(domNode);
34+
const root = reactDomClient!.createRoot(domNode);
3335
root.render(reactElement);
3436
return root;
3537
}
3638

3739
// eslint-disable-next-line react/no-render-return-value
3840
return ReactDOM.render(reactElement, domNode);
3941
}
40-
/* eslint-enable react/no-deprecated */
42+
/* eslint-enable react/no-deprecated,@typescript-eslint/no-deprecated,@typescript-eslint/no-non-null-assertion */
4143

4244
export default function reactHydrateOrRender(
4345
domNode: Element,

node_package/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export interface Root {
166166
unmount(): void;
167167
}
168168

169+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type -- inherited from React 16/17, can't avoid here
169170
export type RenderReturnType = void | Element | Component | Root;
170171

171172
export interface ReactOnRails {

0 commit comments

Comments
 (0)