Skip to content
Myr

chore(lint): set `curly` rule as `all` (#2112)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* chore(lint): set `curly` rule as `all` * denoify

authored by Yusuke Wada · committed by GitHub · parent 4031fa8 · Browse files · 31 files+214 added−76 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

31 files+214 added−76 removed

  • tests:+6 added−2 removed
  • other:+208 added−74 removed

31 files+214 added−76 removed

modified:deno_dist/adapter/deno/serve-static.ts+3 added-1 removed
modified:deno_dist/client/client.ts+6 added-2 removed
6 unmodified lines
78const createProxy = (callback: Callback, path: string[]) => {9 const proxy: unknown = new Proxy(() => {}, {10 get(_obj, key) {11 if (typeof key !== 'string' || key === 'then') return undefined11 if (typeof key !== 'string' || key === 'then') {12 return undefined13 }14 return createProxy(callback, [...path, key])15 },16 apply(_1, _2, args) {17 return callback({
83 unmodified lines
101 }102 headerValues['Cookie'] = cookies.join(',')103 }104103 if (this.cType) headerValues['Content-Type'] = this.cType105 if (this.cType) {106 headerValues['Content-Type'] = this.cType107 }108109 const headers = new Headers(headerValues ?? undefined)110 let url = this.url111
51 unmodified lines
modified:deno_dist/helper/adapter/index.ts+21 added-7 removed
modified:deno_dist/helper/cookie/index.ts+12 added-4 removed
modified:deno_dist/router/reg-exp-router/router.ts+3 added-1 removed
135 unmodified lines
136 if (!middleware || !routes) {137 throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT)138 }139140 if (methodNames.indexOf(method) === -1) methodNames.push(method)140 if (methodNames.indexOf(method) === -1) {141 methodNames.push(method)142 }143 if (!middleware[method]) {144 ;[middleware, routes].forEach((handlerMap) => {145 handlerMap[method] = {}146 Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
129 unmodified lines
modified:deno_dist/router/trie-router/node.ts+6 added-2 removed
51 unmodified lines
52 if (Object.keys(curNode.children).includes(p)) {53 parentPatterns.push(...curNode.patterns)54 curNode = curNode.children[p]55 const pattern = getPattern(p)56 if (pattern) possibleKeys.push(pattern[1])56 if (pattern) {57 possibleKeys.push(pattern[1])58 }59 continue60 }6162 curNode.children[p] = new Node()
98 unmodified lines
161 }162 continue163 }164163 if (part === '') continue165 if (part === '') {166 continue167 }168169 const [key, name, matcher] = pattern170171 const child = node.children[key]
35 unmodified lines
modified:deno_dist/utils/cookie.ts+19 added-7 removed
34 unmodified lines
35): Promise<boolean> => {36 try {37 const signatureBinStr = atob(base64Signature)38 const signature = new Uint8Array(signatureBinStr.length)39 for (let i = 0; i < signatureBinStr.length; i++) signature[i] = signatureBinStr.charCodeAt(i)39 for (let i = 0; i < signatureBinStr.length; i++) {40 signature[i] = signatureBinStr.charCodeAt(i)41 }42 return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value))43 } catch (e) {44 return false45 }
14 unmodified lines
60 const pairs = cookie.trim().split(';')61 return pairs.reduce((parsedCookie, pairStr) => {62 pairStr = pairStr.trim()63 const valueStartPos = pairStr.indexOf('=')62 if (valueStartPos === -1) return parsedCookie64 if (valueStartPos === -1) {65 return parsedCookie66 }6768 const cookieName = pairStr.substring(0, valueStartPos).trim()65 if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) return parsedCookie69 if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) {70 return parsedCookie71 }7273 let cookieValue = pairStr.substring(valueStartPos + 1).trim()68 if (cookieValue.startsWith('"') && cookieValue.endsWith('"'))74 if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {75 cookieValue = cookieValue.slice(1, -1)76 }70 if (validCookieValueRegEx.test(cookieValue))77 if (validCookieValueRegEx.test(cookieValue)) {78 parsedCookie[cookieName] = decodeURIComponent_(cookieValue)79 }8081 return parsedCookie82 }, {} as Cookie)83}
7 unmodified lines
91 const secretKey = await getCryptoKey(secret)9293 for (const [key, value] of Object.entries(parse(cookie, name))) {94 const signatureStartPos = value.lastIndexOf('.')87 if (signatureStartPos < 1) continue95 if (signatureStartPos < 1) {96 continue97 }9899 const signedValue = value.substring(0, signatureStartPos)100 const signature = value.substring(signatureStartPos + 1)91 if (signature.length !== 44 || !signature.endsWith('=')) continue101 if (signature.length !== 44 || !signature.endsWith('=')) {102 continue103 }104105 const isVerified = await verifySignature(signature, signedValue, secretKey)106 parsedCookie[key] = isVerified ? signedValue : false107 }
58 unmodified lines
modified:deno_dist/utils/filepath.ts+3 added-1 removed
4 unmodified lines
5}67export const getFilePath = (options: FilePathOptions): string | undefined => {8 let filename = options.filename9 if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return9 if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {10 return11 }1213 let root = options.root || ''14 const defaultDocument = options.defaultDocument || 'index.html'15
23 unmodified lines
modified:deno_dist/utils/mime.ts+3 added-1 removed
1export const getMimeType = (filename: string): string | undefined => {2 const regexp = /\.([a-zA-Z0-9]+?)$/3 const match = filename.match(regexp)4 if (!match) return4 if (!match) {5 return6 }7 let mimeType = mimes[match[1]]8 if ((mimeType && mimeType.startsWith('text')) || mimeType === 'application/json') {9 mimeType += '; charset=utf-8'10 }
84 unmodified lines
modified:deno_dist/utils/url.ts+3 added-1 removed
124 unmodified lines
125 [`/api/animals`, `/api/animals/:type`]126 in other cases it will return null127 */128129 if (!path.match(/\:.+\?$/)) return null129 if (!path.match(/\:.+\?$/)) {130 return null131 }132133 const segments = path.split('/')134 const results: string[] = []135 let basePath = ''
132 unmodified lines
modified:deno_dist/hono-base.ts+6 added-2 removed
99 unmodified lines
100 })101102 // Implementation of app.on(method, path, ...handlers[])103 this.on = (method: string | string[], path: string, ...handlers: H[]) => {104 if (!method) return this104 if (!method) {105 return this106 }107 this.#path = path108 for (const m of [method].flat()) {109 handlers.map((handler) => {110 this.addRoute(m.toUpperCase(), this.#path, handler)
126 unmodified lines
237 ),238 ...optionsArray239 )240239 if (res) return res241 if (res) {242 return res243 }244245 await next()246 }247 this.addRoute(METHOD_NAME_ALL, mergePath(path, '*'), handler)
142 unmodified lines
modified:deno_dist/request.ts+12 added-4 removed
92 unmodified lines
9394 header(name: string): string | undefined95 header(): Record<string, string>96 header(name?: string) {97 if (name) {97 if (name) return this.raw.headers.get(name.toLowerCase()) ?? undefined98 return this.raw.headers.get(name.toLowerCase()) ?? undefined99 }100101 const headerData: Record<string, string | undefined> = {}102 this.raw.headers.forEach((value, key) => {103 headerData[key] = value
24 unmodified lines
128 cookie(): Cookie129130 cookie(key?: string) {131 const cookie = this.raw.headers.get('Cookie')130 if (!cookie) return132 if (!cookie) {133 return134 }135 const obj = parse(cookie)136 if (key) {137 const value = obj[key]138 return value
2 unmodified lines
141 }142 }143144 async parseBody<T extends BodyData = BodyData>(options?: ParseBodyOptions): Promise<T> {141 if (this.bodyCache.parsedBody) return this.bodyCache.parsedBody as T145 if (this.bodyCache.parsedBody) {146 return this.bodyCache.parsedBody as T147 }148 const parsedBody = await parseBody<T>(this, options)149 this.bodyCache.parsedBody = parsedBody150 return parsedBody151 }152153 private cachedBody = (key: keyof Body) => {154 const { bodyCache, raw } = this155 const cachedBody = bodyCache[key]150 if (cachedBody) return cachedBody156 if (cachedBody) {157 return cachedBody158 }159 /**160 * If an arrayBuffer cache is exist,161 * use it for creating a text, json, and others.162 */
109 unmodified lines
modified:runtime_tests/lambda/index.test.ts+3 added-1 removed
131 unmodified lines
132 app.get('/cookie', (c) => {133 const validCookies =134 getCookie(c, testCookie1.key) === testCookie1.value &&135 getCookie(c, testCookie2.key) === testCookie2.value136 if (!validCookies) return c.text('Invalid Cookies')136 if (!validCookies) {137 return c.text('Invalid Cookies')138 }139 return c.text('Valid Cookies')140 })141142 const handler = handle(app)
515 unmodified lines
modified:src/adapter/aws-lambda/handler.ts+3 added-1 removed
202 unmodified lines
203204 const headers = new Headers()205 getCookies(event, headers)206 for (const [k, v] of Object.entries(event.headers)) {207 if (v) {207 if (v) headers.set(k, v)208 headers.set(k, v)209 }210 }211212 const method = isProxyEventV2(event) ? event.requestContext.http.method : event.httpMethod213 const requestInit: RequestInit = {
58 unmodified lines
modified:src/adapter/bun/serve-static.ts+3 added-1 removed
34 unmodified lines
35 root: options.root,36 defaultDocument: DEFAULT_DOCUMENT,37 })3839 if (!path) return await next()39 if (!path) {40 return await next()41 }4243 path = `./${path}`4445 if (existsSync(path)) {
16 unmodified lines
modified:src/adapter/cloudflare-workers/serve-static.ts+3 added-1 removed
34 unmodified lines
35 root: options.root,36 defaultDocument: DEFAULT_DOCUMENT,37 })3839 if (!path) return await next()39 if (!path) {40 return await next()41 }4243 const content = await getContentFromKVAsset(path, {44 manifest: options.manifest,45 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18 unmodified lines
modified:src/adapter/deno/serve-static.ts+3 added-1 removed
32 unmodified lines
33 root: options.root,34 defaultDocument: DEFAULT_DOCUMENT,35 })3637 if (!path) return await next()37 if (!path) {38 return await next()39 }4041 path = `./${path}`4243 let file
21 unmodified lines
modified:src/client/client.ts+6 added-2 removed
6 unmodified lines
78const createProxy = (callback: Callback, path: string[]) => {9 const proxy: unknown = new Proxy(() => {}, {10 get(_obj, key) {11 if (typeof key !== 'string' || key === 'then') return undefined11 if (typeof key !== 'string' || key === 'then') {12 return undefined13 }14 return createProxy(callback, [...path, key])15 },16 apply(_1, _2, args) {17 return callback({
83 unmodified lines
101 }102 headerValues['Cookie'] = cookies.join(',')103 }104103 if (this.cType) headerValues['Content-Type'] = this.cType105 if (this.cType) {106 headerValues['Content-Type'] = this.cType107 }108109 const headers = new Headers(headerValues ?? undefined)110 let url = this.url111
51 unmodified lines
modified:src/helper/adapter/index.ts+21 added-7 removed
41 unmodified lines
42export const getRuntimeKey = () => {43 // eslint-disable-next-line @typescript-eslint/no-explicit-any44 const global = globalThis as any4546 if (global?.Deno !== undefined) return 'deno'47 if (global?.Bun !== undefined) return 'bun'48 if (typeof global?.WebSocketPair === 'function') return 'workerd'49 if (typeof global?.EdgeRuntime === 'string') return 'edge-light'50 if (global?.fastly !== undefined) return 'fastly'51 if (global?.__lagon__ !== undefined) return 'lagon'52 if (global?.process?.release?.name === 'node') return 'node'46 if (global?.Deno !== undefined) {47 return 'deno'48 }49 if (global?.Bun !== undefined) {50 return 'bun'51 }52 if (typeof global?.WebSocketPair === 'function') {53 return 'workerd'54 }55 if (typeof global?.EdgeRuntime === 'string') {56 return 'edge-light'57 }58 if (global?.fastly !== undefined) {59 return 'fastly'60 }61 if (global?.__lagon__ !== undefined) {62 return 'lagon'63 }64 if (global?.process?.release?.name === 'node') {65 return 'node'66 }6768 return 'other'69}
modified:src/helper/cookie/index.test.ts+3 added-1 removed
120 unmodified lines
121122 app.get('/cookie', (c) => {123 const yummyCookie = getCookie(c, 'yummy_cookie')124 const res = new Response('Good cookie')125 if (yummyCookie) res.headers.set('Yummy-Cookie', yummyCookie)125 if (yummyCookie) {126 res.headers.set('Yummy-Cookie', yummyCookie)127 }128 return res129 })130131 it('Should be null', async () => {
172 unmodified lines
modified:src/helper/cookie/index.ts+12 added-4 removed
13 unmodified lines
1415export const getCookie: GetCookie = (c, key?) => {16 const cookie = c.req.raw.headers.get('Cookie')17 if (typeof key === 'string') {18 if (!cookie) return undefined18 if (!cookie) {19 return undefined20 }21 const obj = parse(cookie, key)22 return obj[key]23 }22 if (!cookie) return {}24 if (!cookie) {25 return {}26 }27 const obj = parse(cookie)28 // eslint-disable-next-line @typescript-eslint/no-explicit-any29 return obj as any30}3132export const getSignedCookie: GetSignedCookie = async (c, secret, key?) => {33 const cookie = c.req.raw.headers.get('Cookie')34 if (typeof key === 'string') {31 if (!cookie) return undefined35 if (!cookie) {36 return undefined37 }38 const obj = await parseSigned(cookie, secret, key)39 return obj[key]40 }35 if (!cookie) return {}41 if (!cookie) {42 return {}43 }44 const obj = await parseSigned(cookie, secret)45 // eslint-disable-next-line @typescript-eslint/no-explicit-any46 return obj as any47}
20 unmodified lines
modified:src/router/reg-exp-router/router.ts+3 added-1 removed
135 unmodified lines
136 if (!middleware || !routes) {137 throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT)138 }139140 if (methodNames.indexOf(method) === -1) methodNames.push(method)140 if (methodNames.indexOf(method) === -1) {141 methodNames.push(method)142 }143 if (!middleware[method]) {144 ;[middleware, routes].forEach((handlerMap) => {145 handlerMap[method] = {}146 Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
129 unmodified lines
modified:src/router/trie-router/node.ts+6 added-2 removed
51 unmodified lines
52 if (Object.keys(curNode.children).includes(p)) {53 parentPatterns.push(...curNode.patterns)54 curNode = curNode.children[p]55 const pattern = getPattern(p)56 if (pattern) possibleKeys.push(pattern[1])56 if (pattern) {57 possibleKeys.push(pattern[1])58 }59 continue60 }6162 curNode.children[p] = new Node()
98 unmodified lines
161 }162 continue163 }164163 if (part === '') continue165 if (part === '') {166 continue167 }168169 const [key, name, matcher] = pattern170171 const child = node.children[key]
35 unmodified lines
modified:src/utils/cookie.ts+19 added-7 removed
34 unmodified lines
35): Promise<boolean> => {36 try {37 const signatureBinStr = atob(base64Signature)38 const signature = new Uint8Array(signatureBinStr.length)39 for (let i = 0; i < signatureBinStr.length; i++) signature[i] = signatureBinStr.charCodeAt(i)39 for (let i = 0; i < signatureBinStr.length; i++) {40 signature[i] = signatureBinStr.charCodeAt(i)41 }42 return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value))43 } catch (e) {44 return false45 }
14 unmodified lines
60 const pairs = cookie.trim().split(';')61 return pairs.reduce((parsedCookie, pairStr) => {62 pairStr = pairStr.trim()63 const valueStartPos = pairStr.indexOf('=')62 if (valueStartPos === -1) return parsedCookie64 if (valueStartPos === -1) {65 return parsedCookie66 }6768 const cookieName = pairStr.substring(0, valueStartPos).trim()65 if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) return parsedCookie69 if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) {70 return parsedCookie71 }7273 let cookieValue = pairStr.substring(valueStartPos + 1).trim()68 if (cookieValue.startsWith('"') && cookieValue.endsWith('"'))74 if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {75 cookieValue = cookieValue.slice(1, -1)76 }70 if (validCookieValueRegEx.test(cookieValue))77 if (validCookieValueRegEx.test(cookieValue)) {78 parsedCookie[cookieName] = decodeURIComponent_(cookieValue)79 }8081 return parsedCookie82 }, {} as Cookie)83}
7 unmodified lines
91 const secretKey = await getCryptoKey(secret)9293 for (const [key, value] of Object.entries(parse(cookie, name))) {94 const signatureStartPos = value.lastIndexOf('.')87 if (signatureStartPos < 1) continue95 if (signatureStartPos < 1) {96 continue97 }9899 const signedValue = value.substring(0, signatureStartPos)100 const signature = value.substring(signatureStartPos + 1)91 if (signature.length !== 44 || !signature.endsWith('=')) continue101 if (signature.length !== 44 || !signature.endsWith('=')) {102 continue103 }104105 const isVerified = await verifySignature(signature, signedValue, secretKey)106 parsedCookie[key] = isVerified ? signedValue : false107 }
58 unmodified lines
modified:src/utils/filepath.ts+3 added-1 removed
4 unmodified lines
5}67export const getFilePath = (options: FilePathOptions): string | undefined => {8 let filename = options.filename9 if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return9 if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {10 return11 }1213 let root = options.root || ''14 const defaultDocument = options.defaultDocument || 'index.html'15
23 unmodified lines
modified:src/utils/mime.ts+3 added-1 removed
1export const getMimeType = (filename: string): string | undefined => {2 const regexp = /\.([a-zA-Z0-9]+?)$/3 const match = filename.match(regexp)4 if (!match) return4 if (!match) {5 return6 }7 let mimeType = mimes[match[1]]8 if ((mimeType && mimeType.startsWith('text')) || mimeType === 'application/json') {9 mimeType += '; charset=utf-8'10 }
84 unmodified lines
modified:src/utils/url.ts+3 added-1 removed
124 unmodified lines
125 [`/api/animals`, `/api/animals/:type`]126 in other cases it will return null127 */128129 if (!path.match(/\:.+\?$/)) return null129 if (!path.match(/\:.+\?$/)) {130 return null131 }132133 const segments = path.split('/')134 const results: string[] = []135 let basePath = ''
132 unmodified lines
modified:src/hono-base.ts+6 added-2 removed
99 unmodified lines
100 })101102 // Implementation of app.on(method, path, ...handlers[])103 this.on = (method: string | string[], path: string, ...handlers: H[]) => {104 if (!method) return this104 if (!method) {105 return this106 }107 this.#path = path108 for (const m of [method].flat()) {109 handlers.map((handler) => {110 this.addRoute(m.toUpperCase(), this.#path, handler)
126 unmodified lines
237 ),238 ...optionsArray239 )240239 if (res) return res241 if (res) {242 return res243 }244245 await next()246 }247 this.addRoute(METHOD_NAME_ALL, mergePath(path, '*'), handler)
142 unmodified lines
modified:src/request.ts+12 added-4 removed
92 unmodified lines
9394 header(name: string): string | undefined95 header(): Record<string, string>96 header(name?: string) {97 if (name) {97 if (name) return this.raw.headers.get(name.toLowerCase()) ?? undefined98 return this.raw.headers.get(name.toLowerCase()) ?? undefined99 }100101 const headerData: Record<string, string | undefined> = {}102 this.raw.headers.forEach((value, key) => {103 headerData[key] = value
24 unmodified lines
128 cookie(): Cookie129130 cookie(key?: string) {131 const cookie = this.raw.headers.get('Cookie')130 if (!cookie) return132 if (!cookie) {133 return134 }135 const obj = parse(cookie)136 if (key) {137 const value = obj[key]138 return value
2 unmodified lines
141 }142 }143144 async parseBody<T extends BodyData = BodyData>(options?: ParseBodyOptions): Promise<T> {141 if (this.bodyCache.parsedBody) return this.bodyCache.parsedBody as T145 if (this.bodyCache.parsedBody) {146 return this.bodyCache.parsedBody as T147 }148 const parsedBody = await parseBody<T>(this, options)149 this.bodyCache.parsedBody = parsedBody150 return parsedBody151 }152153 private cachedBody = (key: keyof Body) => {154 const { bodyCache, raw } = this155 const cachedBody = bodyCache[key]150 if (cachedBody) return cachedBody156 if (cachedBody) {157 return cachedBody158 }159 /**160 * If an arrayBuffer cache is exist,161 * use it for creating a text, json, and others.162 */
109 unmodified lines
modified:package.json+1 added-1 removed
470 unmodified lines
471 "nodejs"472 ],473 "devDependencies": {474 "@cloudflare/workers-types": "^4.20231121.0",475 "@hono/eslint-config": "^0.0.3",475 "@hono/eslint-config": "^0.0.4",476 "@hono/node-server": "^1.3.3",477 "@types/crypto-js": "^4.1.1",478 "@types/glob": "^8.0.0",479 "@types/jsdom": "^21.1.4",
30 unmodified lines
modified:yarn.lock+4 added-4 removed
494 unmodified lines
495 integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==496 dependencies:497 "@hapi/hoek" "^9.0.0"498499"@hono/eslint-config@^0.0.3":500 version "0.0.3"501 resolved "https://registry.yarnpkg.com/@hono/eslint-config/-/eslint-config-0.0.3.tgz#15978d401c53c5497156f0a80dc2b261e94139c9"502 integrity sha512-A4pbMilmx+HpY9TPZuC7+1eEhdTfTWKo7wJjWULOkJiH3pf580ZhaRZ+GvArCDPW6YkvTVvaGxr0wkt8VApzDg==499"@hono/eslint-config@^0.0.4":500 version "0.0.4"501 resolved "https://registry.yarnpkg.com/@hono/eslint-config/-/eslint-config-0.0.4.tgz#11bf12fd606b63302b4c4f5880f6965cc33ddcd2"502 integrity sha512-CaL3LBdI2tw7Luo4vGDhhrdntA02Nsts6P0FjAz3U5piy3UhWzgEvEN+L9M0fsG7Mm1cgd+kM3hF8CRJOH0aGA==503 dependencies:504 "@typescript-eslint/eslint-plugin" "^6.14.0"505 "@typescript-eslint/parser" "^6.14.0"506 eslint-config-prettier "^9.1.0"
6387 unmodified lines