diff --git a/.eslintrc b/.eslintrc index 5c5387ff7..b7cd56760 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,6 +12,7 @@ ], "parser": "@typescript-eslint/parser", "rules": { + "@typescript-eslint/explicit-function-return-type": "error", "@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-empty-function": "error", // Enforce return types on exported functions or public methods diff --git a/sandpack-client/src/client.ts b/sandpack-client/src/client.ts index db0660876..f43faa83c 100644 --- a/sandpack-client/src/client.ts +++ b/sandpack-client/src/client.ts @@ -348,7 +348,7 @@ export class SandpackClient { this.dispatch({ type: "get-transpiler-context" }); }); - private getFiles() { + private getFiles(): SandpackBundlerFiles { const { sandboxInfo } = this; if (sandboxInfo.files["/package.json"] === undefined) { @@ -363,7 +363,7 @@ export class SandpackClient { return this.sandboxInfo.files; } - private initializeElement() { + private initializeElement(): void { this.iframe.style.border = "0"; this.iframe.style.width = this.options.width || "100%"; this.iframe.style.height = this.options.height || "100%"; diff --git a/sandpack-client/src/iframe-protocol.ts b/sandpack-client/src/iframe-protocol.ts index 6e7f7f025..625b7dead 100644 --- a/sandpack-client/src/iframe-protocol.ts +++ b/sandpack-client/src/iframe-protocol.ts @@ -77,7 +77,7 @@ export class IFrameProtocol { // This is needed for the `initialize` message which comes without a channelId globalListen(listener: ListenerFunction): UnsubscribeFunction { if (typeof listener !== "function") { - return () => { + return (): void => { return; }; } @@ -85,7 +85,7 @@ export class IFrameProtocol { const listenerId = this.globalListenersCount; this.globalListeners[listenerId] = listener; this.globalListenersCount++; - return () => { + return (): void => { delete this.globalListeners[listenerId]; }; } @@ -94,7 +94,7 @@ export class IFrameProtocol { // All other messages (eg: from other iframes) are ignored channelListen(listener: ListenerFunction): UnsubscribeFunction { if (typeof listener !== "function") { - return () => { + return (): void => { return; }; } @@ -102,13 +102,13 @@ export class IFrameProtocol { const listenerId = this.channelListenersCount; this.channelListeners[listenerId] = listener; this.channelListenersCount++; - return () => { + return (): void => { delete this.channelListeners[listenerId]; }; } // Handles message windows coming from iframes - private eventListener(message: MessageEvent) { + private eventListener(message: MessageEvent): void { if (!message.data.codesandbox) { return; } diff --git a/sandpack-client/src/utils.ts b/sandpack-client/src/utils.ts index a4294c9cc..f6ca14920 100644 --- a/sandpack-client/src/utils.ts +++ b/sandpack-client/src/utils.ts @@ -81,7 +81,9 @@ export function extractErrorDetails(msg: SandpackErrorMessage): SandpackError { }; } -function getRelevantStackFrame(frames?: ErrorStackFrame[]) { +function getRelevantStackFrame( + frames?: ErrorStackFrame[] +): ErrorStackFrame | undefined { if (!frames) { return; } @@ -89,13 +91,13 @@ function getRelevantStackFrame(frames?: ErrorStackFrame[]) { return frames.find((frame) => !!frame._originalFileName); } -function getErrorLocation(errorFrame: ErrorStackFrame) { +function getErrorLocation(errorFrame: ErrorStackFrame): string { return errorFrame ? ` (${errorFrame._originalLineNumber}:${errorFrame._originalColumnNumber})` : ``; } -function getErrorInOriginalCode(errorFrame: ErrorStackFrame) { +function getErrorInOriginalCode(errorFrame: ErrorStackFrame): string { const lastScriptLine = errorFrame._originalScriptCode[errorFrame._originalScriptCode.length - 1]; const numberOfLineNumberCharacters = @@ -138,7 +140,7 @@ function formatErrorMessage( message: string, location: string, errorInCode: string -) { +): string { return `${filePath}: ${message}${location} ${errorInCode}`; } diff --git a/sandpack-react/src/common/RunButton.tsx b/sandpack-react/src/common/RunButton.tsx index a6af38188..40101f9f4 100644 --- a/sandpack-react/src/common/RunButton.tsx +++ b/sandpack-react/src/common/RunButton.tsx @@ -14,7 +14,7 @@ export const RunButton: React.FC = () => { return ( ); }; -const CustomCodeEditor = () => { +const CustomCodeEditor: React.FC = () => { const { code, updateCode } = useActiveCode(); const { theme } = useSandpackTheme(); return (