From f7d2a53a2efb4e0420b53283be519b434ddbc26c Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 19 Jan 2025 09:35:11 +0800 Subject: [PATCH] feat: make lint happy --- libraries/deno-commons-mod.ts | 18 +++++++++--------- libraries/deno-dingtalk-mod.ts | 4 +++- libraries/deno-sshsig-mod.ts | 32 ++++++++++++++++---------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/libraries/deno-commons-mod.ts b/libraries/deno-commons-mod.ts index a78c52a..821b7cc 100644 --- a/libraries/deno-commons-mod.ts +++ b/libraries/deno-commons-mod.ts @@ -1,24 +1,24 @@ export function compareVersion(ver1: string, ver2: string) { if (ver1 === ver2) { return 0; } - let ver1Parts = ver1.split("."); - let ver2Parts = ver2.split("."); - let ver1Main = parseInt(ver1Parts[0]); - let ver2Main = parseInt(ver2Parts[0]); + const ver1Parts = ver1.split("."); + const ver2Parts = ver2.split("."); + const ver1Main = parseInt(ver1Parts[0]); + const ver2Main = parseInt(ver2Parts[0]); if (ver1Main > ver2Main) { return 1; } if (ver1Main < ver2Main) { return -1; } - let ver1Second = parseInt(ver1Parts[1]); - let ver2Second = parseInt(ver2Parts[1]); + const ver1Second = parseInt(ver1Parts[1]); + const ver2Second = parseInt(ver2Parts[1]); if (ver1Second > ver2Second) { return 1; } if (ver1Second < ver2Second) { return -1; } - let ver1Third = parseInt(ver1Parts[2]); - let ver2Third = parseInt(ver2Parts[2]); + const ver1Third = parseInt(ver1Parts[2]); + const ver2Third = parseInt(ver2Parts[2]); if (ver1Third > ver2Third) { return 1; } if (ver1Third < ver2Third) { return -1; } return 0; } export function isOn(val: string) { - let lowerVal = (val == null)? val: val.toLowerCase(); + const lowerVal = (val == null)? val: val.toLowerCase(); return lowerVal === "on" || lowerVal === "yes" || lowerVal === "1" || lowerVal === "true"; } diff --git a/libraries/deno-dingtalk-mod.ts b/libraries/deno-dingtalk-mod.ts index e595785..aaba770 100644 --- a/libraries/deno-dingtalk-mod.ts +++ b/libraries/deno-dingtalk-mod.ts @@ -1,5 +1,6 @@ import { hmac } from "https://deno.land/x/hmac@v2.0.1/mod.ts"; +// deno-lint-ignore no-explicit-any async function postHttpJson(url: string, body: any) { const resp = await fetch(url, { method: "POST", @@ -59,13 +60,14 @@ export async function sendDingTalkMarkdownMessage(message: DingTalkMarkdownMessa }, options); } +// deno-lint-ignore no-explicit-any export async function sendDingTalkMessage(message: any, options: SendDingTalkMessageOptions) { let send_url = options.base_url || BASE_DING_TALK_URL; send_url += "?access_token=" + encodeURIComponent(options.access_token); if (options.sec_token) { const timestamp = new Date().getTime(); const timestamp_and_secret = `${timestamp}\n${options.sec_token}`; - const sec_token_sign = hmac("sha256", options.sec_token, timestamp_and_secret, "utf8", "base64"); + const sec_token_sign = hmac("sha256", options.sec_token, timestamp_and_secret, "utf8", "base64") as string; send_url += "×tamp=" + timestamp; send_url += "&sign=" + encodeURIComponent(sec_token_sign); } diff --git a/libraries/deno-sshsig-mod.ts b/libraries/deno-sshsig-mod.ts index e4c4fab..9c7574d 100644 --- a/libraries/deno-sshsig-mod.ts +++ b/libraries/deno-sshsig-mod.ts @@ -58,7 +58,7 @@ class BinaryWriter { for (let i = 0; i < this.buffers.length; i++) { totalLen += this.buffers[i].byteLength; } - let merged = new Uint8Array(totalLen); + const merged = new Uint8Array(totalLen); let offset = 0; for (let i = 0; i < this.buffers.length; i++) { merged.set(this.buffers[i], offset); @@ -83,13 +83,13 @@ class BinaryWriter { } writeUint32(num: number) { - let dataView = new DataView(new ArrayBuffer(4), 0); + const dataView = new DataView(new ArrayBuffer(4), 0); dataView.setUint32(0, num); this.writeBytes(new Uint8Array(dataView.buffer)); } writeNumber(num: number) { - let n = new Uint8Array(1) + const n = new Uint8Array(1) n[0] = num; this.writeBytes(n); } @@ -163,12 +163,12 @@ class SshSignature { } static parse(buffer: Uint8Array): SshSignature { - let reader = new BinaryReader(buffer); + const reader = new BinaryReader(buffer); const sshSig = reader.readLengthToString(6); if (sshSig !== "SSHSIG") { throw `Bad SSH signature magic, expect: SSHSIG, actual: ${sshSig}`; } - let sshVer = reader.readUint32(); + const sshVer = reader.readUint32(); if (sshVer !== 1) { throw `Bad SSH signature version, expect: 1, actual: ${sshVer}`; } @@ -214,7 +214,7 @@ class SshSignature { if (this.getHashAlgorithmLength() !== digest.byteLength) { throw `Bad digest length, expect: ${this.getHashAlgorithmLength()}, acutal: ${digest.byteLength}`; } - let writer = new BinaryWriter(); + const writer = new BinaryWriter(); writer.writeLengthFromString("SSHSIG"); writer.writeStringFromString(this.namespace); writer.writeStringFromString(""); @@ -260,10 +260,10 @@ class SshSignatureValue { } static parse(buffer: Uint8Array): SshSignatureValue { - let reader = new BinaryReader(buffer); + const reader = new BinaryReader(buffer); const signatureAlgorithm = reader.readStringToString(); const signatureEc = reader.readString(); - let signatureEcReader = new BinaryReader(signatureEc); + const signatureEcReader = new BinaryReader(signatureEc); const r = signatureEcReader.readString(); const s = signatureEcReader.readString(); return new SshSignatureValue(signatureAlgorithm, r, s); @@ -271,7 +271,7 @@ class SshSignatureValue { // crypto.subtle.sign's signature is R and S toRs(): Uint8Array { - let writer = new BinaryWriter(); + const writer = new BinaryWriter(); if (this.ecSignatureR.byteLength === 0x21) { writer.writeBytes(this.ecSignatureR.slice(1)); } else { @@ -290,7 +290,7 @@ class SshSignatureValue { // INTEGER: 69658b75c9c7523c15e6de16907350f0d0fd51114237c3e32bdd9fe92465e768 // } toDer(): Uint8Array { - let writer = new BinaryWriter(); + const writer = new BinaryWriter(); writer.writeNumber(0x30); writer.writeNumber(0x45); @@ -325,7 +325,7 @@ class SshPublicKey { } static parse(buffer: Uint8Array): SshPublicKey { - let reader = new BinaryReader(buffer); + const reader = new BinaryReader(buffer); const signatureAlgorithm = reader.readStringToString(); const curveAlgorithm = reader.readStringToString(); const publicKeyPoint = reader.readString(); @@ -336,7 +336,7 @@ class SshPublicKey { } toDer(): Uint8Array { - let writer = new BinaryWriter(); + const writer = new BinaryWriter(); if (this.algorithm === "nistp256") { writer.writeBytes(decodeHex("3059301306072a8648ce3d020106082a8648ce3d030107034200")); } else { @@ -351,7 +351,7 @@ class SshPublicKey { } async importJwk(): Promise { - let jwk = this.toJwk(); + const jwk = this.toJwk(); return await crypto.subtle.importKey( "jwk", jwk, @@ -392,7 +392,7 @@ class SshPublicKey { function parsePemToArray(pem: string): Uint8Array { const lines = pem.split("\n"); let isInPem = false; - let innerPem = []; + const innerPem = []; for (let i = 0; i < lines.length; i++) { const line = lines[i]; if (isInPem) { @@ -413,14 +413,14 @@ function parsePemToArray(pem: string): Uint8Array { } async function digestString(data: string, algorithm: string): Promise { - let hashAlgorithm = normalizeHashAlgorithm(algorithm); + const hashAlgorithm = normalizeHashAlgorithm(algorithm); const messageBuffer = new TextEncoder().encode(data); const hashBuffer = await crypto.subtle.digest(hashAlgorithm, messageBuffer); return new Uint8Array(hashBuffer); } async function digestFile(filename: string, algorithm: string): Promise { - let hashAlgorithm = normalizeHashAlgorithm(algorithm); + const hashAlgorithm = normalizeHashAlgorithm(algorithm); const file = await Deno.open(filename, {read: true}); const readableStream = file.readable; const hashBuffer = await crypto.subtle.digest(hashAlgorithm, readableStream);