diff --git a/.eslintrc b/.eslintrc index a0532af30..3dd6c3304 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,6 +12,7 @@ ], "parser": "@typescript-eslint/parser", "rules": { + "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-empty-function": "error", // Enforce return types on exported functions or public methods @@ -43,7 +44,7 @@ // Consistently sort props "react/jsx-sort-props": [ - "warn", + "error", { "ignoreCase": true, // key, ref must always come first @@ -57,7 +58,7 @@ // Group module and relative imports "import/order": [ - "warn", + "error", { // Imports are grouped as follows: "groups": [ @@ -79,6 +80,14 @@ } ] }, + "overrides": [ + { + "files": ["*.ts", "*.tsx"], + "rules": { + "@typescript-eslint/explicit-function-return-type": ["error"] + } + } + ], "settings": { "version": "detect" } diff --git a/sandpack-client/src/client.ts b/sandpack-client/src/client.ts index 57b7056e4..374bdcb53 100644 --- a/sandpack-client/src/client.ts +++ b/sandpack-client/src/client.ts @@ -169,9 +169,11 @@ export class SandpackClient { "file-resolver", async (data: { m: "isFile" | "readFile"; p: string }) => { if (data.m === "isFile") { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.options.fileResolver!.isFile(data.p); } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.options.fileResolver!.readFile(data.p); }, this.iframe.contentWindow @@ -349,7 +351,7 @@ export class SandpackClient { this.dispatch({ type: "get-transpiler-context" }); }); - private getFiles() { + private getFiles(): SandpackBundlerFiles { const { sandboxInfo } = this; if (sandboxInfo.files["/package.json"] === undefined) { @@ -364,7 +366,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/ErrorOverlay.tsx b/sandpack-react/src/common/ErrorOverlay.tsx index e89319b20..727dc9423 100644 --- a/sandpack-react/src/common/ErrorOverlay.tsx +++ b/sandpack-react/src/common/ErrorOverlay.tsx @@ -6,7 +6,7 @@ import { useErrorMessage } from "../hooks/useErrorMessage"; /** * @category Components */ -export const ErrorOverlay: React.FC = () => { +export const ErrorOverlay = (): JSX.Element | null => { const errorMessage = useErrorMessage(); const c = useClasser("sp"); diff --git a/sandpack-react/src/common/OpenInCodeSandboxButton/OpenInCodeSandboxButton.tsx b/sandpack-react/src/common/OpenInCodeSandboxButton/OpenInCodeSandboxButton.tsx index 2e0045af0..e56406a1d 100644 --- a/sandpack-react/src/common/OpenInCodeSandboxButton/OpenInCodeSandboxButton.tsx +++ b/sandpack-react/src/common/OpenInCodeSandboxButton/OpenInCodeSandboxButton.tsx @@ -10,7 +10,7 @@ import { UnstyledOpenInCodeSandboxButton } from "./UnstyledOpenInCodeSandboxButt /** * @category Components */ -export const OpenInCodeSandboxButton: React.FC = () => { +export const OpenInCodeSandboxButton = (): JSX.Element | null => { const { theme } = useSandpackTheme(); const c = useClasser("sp"); diff --git a/sandpack-react/src/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx b/sandpack-react/src/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx index e1547382f..6e5bd7a1b 100644 --- a/sandpack-react/src/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx +++ b/sandpack-react/src/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx @@ -10,7 +10,7 @@ const CSB_URL = "https://codesandbox.io/api/v1/sandboxes/define"; const getFileParameters = ( files: SandpackBundlerFiles, environment?: SandboxEnvironment -) => { +): string => { type NormalizedFiles = Record< string, { @@ -50,7 +50,7 @@ export const UnstyledOpenInCodeSandboxButton: React.FC< setParamsValues(params); }, 600); - return () => { + return (): void => { clearTimeout(timer); }; }, @@ -60,6 +60,7 @@ export const UnstyledOpenInCodeSandboxButton: React.FC< // Register the usage of the codesandbox link React.useEffect(function registerUsage() { sandpack.openInCSBRegisteredRef.current = true; + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); /** @@ -69,7 +70,7 @@ export const UnstyledOpenInCodeSandboxButton: React.FC< if (paramsValues.length > 1500) { return (