Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add return types of void function #2870

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adapter/aws-lambda/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const getRequestContext = (
const streamToNodeStream = async (
reader: ReadableStreamDefaultReader<Uint8Array>,
writer: NodeJS.WritableStream
) => {
): Promise<void> => {
let readResult = await reader.read()
while (!readResult.done) {
writer.write(readResult.value)
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export class Context<
* ```
* @see https://hono.dev/api/context#render-setrenderer
*/
setRenderer = (renderer: Renderer) => {
setRenderer = (renderer: Renderer): void => {
this.renderer = renderer
}

Expand Down
2 changes: 1 addition & 1 deletion src/helper/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const inspectRoutes = <E extends Env>(hono: Hono<E>): RouteData[] => {
})
}

export const showRoutes = <E extends Env>(hono: Hono<E>, opts?: ShowRoutesOptions) => {
export const showRoutes = <E extends Env>(hono: Hono<E>, opts?: ShowRoutesOptions): void => {
const colorEnabled = opts?.colorize ?? getColorEnabled()
const routeData: Record<string, RouteData[]> = {}
let maxMethodLength = 0
Expand Down
2 changes: 1 addition & 1 deletion src/helper/streaming/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const run = async (
stream: SSEStreamingApi,
cb: (stream: SSEStreamingApi) => Promise<void>,
onError?: (e: Error, stream: SSEStreamingApi) => Promise<void>
) => {
): Promise<void> => {
try {
await cb(stream)
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string =
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
*/
fire = () => {
fire = (): void => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
addEventListener('fetch', (event: FetchEventLike): void => {
Expand Down
26 changes: 15 additions & 11 deletions src/jsx/dom/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ const toAttributeName = (element: SupportedElement, key: string): string =>
? key.replace(/([A-Z])/g, '-$1').toLowerCase()
: key

const applyProps = (container: SupportedElement, attributes: Props, oldAttributes?: Props) => {
const applyProps = (
container: SupportedElement,
attributes: Props,
oldAttributes?: Props
): void => {
attributes ||= {}
for (const [key, value] of Object.entries(attributes)) {
if (!skipProps.has(key) && (!oldAttributes || oldAttributes[key] !== value)) {
Expand Down Expand Up @@ -235,7 +239,7 @@ const getNextChildren = (
nextChildren: Node[],
childrenToRemove: Node[],
callbacks: EffectData[]
) => {
): void => {
childrenToRemove.push(...node.vR)
if (typeof node.tag === 'function') {
node[DOM_STASH][1][STASH_EFFECT]?.forEach((data: EffectData) => callbacks.push(data))
Expand Down Expand Up @@ -276,7 +280,7 @@ const findInsertBefore = (node: Node | undefined): SupportedElement | Text | nul
return findInsertBefore(node.nN)
}

const removeNode = (node: Node) => {
const removeNode = (node: Node): void => {
if (!isNodeString(node)) {
node[DOM_STASH]?.[1][STASH_EFFECT]?.forEach((data: EffectData) => data[2]?.())

Expand All @@ -298,12 +302,12 @@ const removeNode = (node: Node) => {
}
}

const apply = (node: NodeObject, container: Container) => {
const apply = (node: NodeObject, container: Container): void => {
node.c = container
applyNodeObject(node, container)
}

const applyNode = (node: Node, container: Container) => {
const applyNode = (node: Node, container: Container): void => {
if (isNodeString(node)) {
container.textContent = node.t
} else {
Expand All @@ -328,7 +332,7 @@ const findChildNodeIndex = (
return
}

const applyNodeObject = (node: NodeObject, container: Container) => {
const applyNodeObject = (node: NodeObject, container: Container): void => {
const next: Node[] = []
const remove: Node[] = []
const callbacks: EffectData[] = []
Expand Down Expand Up @@ -523,14 +527,14 @@ export const buildNode = (node: Child): Node | undefined => {
}
}

const replaceContainer = (node: NodeObject, from: DocumentFragment, to: Container) => {
const replaceContainer = (node: NodeObject, from: DocumentFragment, to: Container): void => {
if (node.c === from) {
node.c = to
node.vC.forEach((child) => replaceContainer(child as NodeObject, from, to))
}
}

const updateSync = (context: Context, node: NodeObject) => {
const updateSync = (context: Context, node: NodeObject): void => {
node[DOM_STASH][2]?.forEach(([c, v]) => {
c.values.push(v)
})
Expand Down Expand Up @@ -590,7 +594,7 @@ export const update = async (
return promise
}

export const renderNode = (node: NodeObject, container: Container) => {
export const renderNode = (node: NodeObject, container: Container): void => {
const context: Context = []
;(context as Context)[4] = true // start top level render
build(context, node, undefined)
Expand All @@ -602,12 +606,12 @@ export const renderNode = (node: NodeObject, container: Container) => {
container.replaceChildren(fragment)
}

export const render = (jsxNode: Child, container: Container) => {
export const render = (jsxNode: Child, container: Container): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
renderNode(buildNode({ tag: '', props: { children: jsxNode } } as any) as NodeObject, container)
}

export const flushSync = (callback: () => void) => {
export const flushSync = (callback: () => void): void => {
const set = new Set<NodeObject>()
currentUpdateSets.push(set)
callback()
Expand Down
Loading