diff --git a/assert/_diff.ts b/assert/_diff.ts index f75f0ff87..c6266ff3c 100644 --- a/assert/_diff.ts +++ b/assert/_diff.ts @@ -351,7 +351,8 @@ export function diffstr(A: string, B: string) { tokenize(`${unescape(B)}\n`), ); - const added = [], removed = []; + const added = []; + const removed = []; for (const result of diffResult) { if (result.type === DiffType.added) { added.push(result); @@ -366,8 +367,8 @@ export function diffstr(A: string, B: string) { const aLines = hasMoreRemovedLines ? added : removed; const bLines = hasMoreRemovedLines ? removed : added; for (const a of aLines) { - let tokens = [] as Array>, - b: undefined | DiffResult; + let tokens = [] as Array>; + let b: undefined | DiffResult; // Search another diff line with at least one common token while (bLines.length) { b = bLines.shift(); @@ -437,7 +438,8 @@ export function buildMessage( diffResult: ReadonlyArray>, { stringDiff = false } = {}, ): string[] { - const messages: string[] = [], diffMessages: string[] = []; + const messages: string[] = []; + const diffMessages: string[] = []; messages.push(""); messages.push(""); messages.push( diff --git a/bytes/ends_with.ts b/bytes/ends_with.ts index bb1ce786b..8dc4dd51d 100644 --- a/bytes/ends_with.ts +++ b/bytes/ends_with.ts @@ -14,11 +14,9 @@ * ``` */ export function endsWith(source: Uint8Array, suffix: Uint8Array): boolean { - for ( - let srci = source.length - 1, sfxi = suffix.length - 1; - sfxi >= 0; - srci--, sfxi-- - ) { + let srci = source.length - 1; + let sfxi = suffix.length - 1; + for (; sfxi >= 0; srci--, sfxi--) { if (source[srci] !== suffix[sfxi]) return false; } return true; diff --git a/bytes/starts_with.ts b/bytes/starts_with.ts index eef3f5d00..dea632ce9 100644 --- a/bytes/starts_with.ts +++ b/bytes/starts_with.ts @@ -14,7 +14,7 @@ * ``` */ export function startsWith(source: Uint8Array, prefix: Uint8Array): boolean { - for (let i = 0, max = prefix.length; i < max; i++) { + for (let i = 0; i < prefix.length; i++) { if (source[i] !== prefix[i]) return false; } return true; diff --git a/csv/stringify.ts b/csv/stringify.ts index 310e474f5..c3a8fb138 100644 --- a/csv/stringify.ts +++ b/csv/stringify.ts @@ -147,8 +147,8 @@ type NormalizedColumn = Omit & { }; function normalizeColumn(column: Column): NormalizedColumn { - let header: NormalizedColumn["header"], - prop: NormalizedColumn["prop"]; + let header: NormalizedColumn["header"]; + let prop: NormalizedColumn["prop"]; if (typeof column === "object") { if (Array.isArray(column)) { diff --git a/deno.json b/deno.json index 3c320d1f7..9db781684 100644 --- a/deno.json +++ b/deno.json @@ -42,7 +42,8 @@ "rules": { "include": [ "camelcase", - "no-sync-fn-in-async-fn" + "no-sync-fn-in-async-fn", + "single-var-declarator" ] } } diff --git a/encoding/ascii85.ts b/encoding/ascii85.ts index c6feba603..10ec4542a 100644 --- a/encoding/ascii85.ts +++ b/encoding/ascii85.ts @@ -65,10 +65,10 @@ export function encodeAscii85( let uint8 = validateBinaryLike(data); const standard = options?.standard ?? "Adobe"; - let output: string[] = [], - v: number, - n = 0, - difference = 0; + let output: string[] = []; + let v: number; + let n = 0; + let difference = 0; if (uint8.length % 4 !== 0) { const tmp = uint8; difference = 4 - (tmp.length % 4); @@ -76,13 +76,13 @@ export function encodeAscii85( uint8.set(tmp); } const view = new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength); - for (let i = 0, len = uint8.length; i < len; i += 4) { + for (let i = 0; i < uint8.length; i += 4) { v = view.getUint32(i); // Adobe and btoa standards compress 4 zeroes to single "z" character if ( (standard === "Adobe" || standard === "btoa") && v === 0 && - i < len - difference - 3 + i < uint8.length - difference - 3 ) { output[n++] = "z"; continue; @@ -164,12 +164,12 @@ export function decodeAscii85( } //remove all invalid characters ascii85 = ascii85.replaceAll(/[^!-u]/g, ""); - const len = ascii85.length, - output = new Uint8Array(len + 4 - (len % 4)); + const len = ascii85.length; + const output = new Uint8Array(len + 4 - (len % 4)); const view = new DataView(output.buffer); - let v = 0, - n = 0, - max = 0; + let v = 0; + let n = 0; + let max = 0; for (let i = 0; i < len;) { for (max += 5; i < max; i++) { v = v * 85 + (i < len ? ascii85.charCodeAt(i) : 117) - 33; diff --git a/encoding/base64.ts b/encoding/base64.ts index 6485af4b0..ae621d095 100644 --- a/encoding/base64.ts +++ b/encoding/base64.ts @@ -95,8 +95,8 @@ const base64abc = [ export function encodeBase64(data: ArrayBuffer | Uint8Array | string): string { // CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727 const uint8 = validateBinaryLike(data); - let result = "", - i; + let result = ""; + let i; const l = uint8.length; for (i = 2; i < l; i += 3) { result += base64abc[(uint8[i - 2]!) >> 2]; diff --git a/encoding/varint.ts b/encoding/varint.ts index 40b4b3958..20146d512 100644 --- a/encoding/varint.ts +++ b/encoding/varint.ts @@ -112,12 +112,11 @@ export function decode(buf: Uint8Array, offset = 0): [bigint, number] { * from the returned new `offset`. */ export function decode32(buf: Uint8Array, offset = 0): [number, number] { + let shift = 0; + let decoded = 0; for ( - let i = offset, - len = Math.min(buf.length, offset + MaxVarIntLen32), - shift = 0, - decoded = 0; - i <= len; + let i = offset; + i <= Math.min(buf.length, offset + MaxVarIntLen32); i += 1, shift += SHIFT ) { const byte = buf[i]!; @@ -148,8 +147,8 @@ export function encode( num = BigInt(num); if (num < 0n) throw new RangeError("signed input given"); for ( - let i = offset, len = Math.min(buf.length, MaxVarIntLen64); - i <= len; + let i = offset; + i <= Math.min(buf.length, MaxVarIntLen64); i += 1 ) { if (num < MSBN) { diff --git a/expect/_diff.ts b/expect/_diff.ts index f75f0ff87..c6266ff3c 100644 --- a/expect/_diff.ts +++ b/expect/_diff.ts @@ -351,7 +351,8 @@ export function diffstr(A: string, B: string) { tokenize(`${unescape(B)}\n`), ); - const added = [], removed = []; + const added = []; + const removed = []; for (const result of diffResult) { if (result.type === DiffType.added) { added.push(result); @@ -366,8 +367,8 @@ export function diffstr(A: string, B: string) { const aLines = hasMoreRemovedLines ? added : removed; const bLines = hasMoreRemovedLines ? removed : added; for (const a of aLines) { - let tokens = [] as Array>, - b: undefined | DiffResult; + let tokens = [] as Array>; + let b: undefined | DiffResult; // Search another diff line with at least one common token while (bLines.length) { b = bLines.shift(); @@ -437,7 +438,8 @@ export function buildMessage( diffResult: ReadonlyArray>, { stringDiff = false } = {}, ): string[] { - const messages: string[] = [], diffMessages: string[] = []; + const messages: string[] = []; + const diffMessages: string[] = []; messages.push(""); messages.push(""); messages.push( diff --git a/path/_common/normalize_string.ts b/path/_common/normalize_string.ts index 57ce7aaf9..d8f0e090a 100644 --- a/path/_common/normalize_string.ts +++ b/path/_common/normalize_string.ts @@ -17,8 +17,8 @@ export function normalizeString( let lastSlash = -1; let dots = 0; let code: number | undefined; - for (let i = 0, len = path.length; i <= len; ++i) { - if (i < len) code = path.charCodeAt(i); + for (let i = 0; i <= path.length; ++i) { + if (i < path.length) code = path.charCodeAt(i); else if (isPathSeparator(code!)) break; else code = CHAR_FORWARD_SLASH; diff --git a/path/posix/join.ts b/path/posix/join.ts index ad4bbae55..625762ab9 100644 --- a/path/posix/join.ts +++ b/path/posix/join.ts @@ -12,7 +12,7 @@ export function join(...paths: string[]): string { if (paths.length === 0) return "."; let joined: string | undefined; - for (let i = 0, len = paths.length; i < len; ++i) { + for (let i = 0; i < paths.length; ++i) { const path = paths[i]!; assertPath(path); if (path.length > 0) { diff --git a/testing/mock.ts b/testing/mock.ts index dd54052c8..b1f7b6d90 100644 --- a/testing/mock.ts +++ b/testing/mock.ts @@ -546,10 +546,10 @@ function methodSpy< } const original = self[property] as unknown as ( - this: Self, - ...args: Args - ) => Return, - calls: SpyCall[] = []; + this: Self, + ...args: Args + ) => Return; + const calls: SpyCall[] = []; let restored = false; const spy = function (this: Self, ...args: Args): Return { const call: SpyCall = { args }; @@ -799,10 +799,10 @@ export function stub< const fake = func ?? (() => {}) as (this: Self, ...args: Args) => Return; const original = self[property] as unknown as ( - this: Self, - ...args: Args - ) => Return, - calls: SpyCall[] = []; + this: Self, + ...args: Args + ) => Return; + const calls: SpyCall[] = []; let restored = false; const stub = function (this: Self, ...args: Args): Return { const call: SpyCall = { args }; diff --git a/yaml/_dumper/dumper.ts b/yaml/_dumper/dumper.ts index a46c75c87..01b310092 100644 --- a/yaml/_dumper/dumper.ts +++ b/yaml/_dumper/dumper.ts @@ -99,12 +99,12 @@ function encodeHex(character: number): string { // Indents every line in a string. Empty lines (\n only) are not indented. function indentString(string: string, spaces: number): string { - const ind = common.repeat(" ", spaces), - length = string.length; - let position = 0, - next = -1, - result = "", - line: string; + const ind = common.repeat(" ", spaces); + const length = string.length; + let position = 0; + let next = -1; + let result = ""; + let line: string; while (position < length) { next = string.indexOf("\n", position); @@ -209,11 +209,11 @@ function needIndentIndicator(string: string): boolean { return leadingSpaceRe.test(string); } -const STYLE_PLAIN = 1, - STYLE_SINGLE = 2, - STYLE_LITERAL = 3, - STYLE_FOLDED = 4, - STYLE_DOUBLE = 5; +const STYLE_PLAIN = 1; +const STYLE_SINGLE = 2; +const STYLE_LITERAL = 3; +const STYLE_FOLDED = 4; +const STYLE_DOUBLE = 5; // Determines which scalar styles are possible and returns the preferred style. // lineWidth = -1 => no limit. @@ -230,13 +230,14 @@ function chooseScalarStyle( testAmbiguousType: (...args: Any[]) => Any, ): number { const shouldTrackWidth = lineWidth !== -1; - let hasLineBreak = false, - hasFoldableLine = false, // only checked if shouldTrackWidth - previousLineBreak = -1, // count the first line correctly - plain = isPlainSafeFirst(string.charCodeAt(0)) && - !isWhitespace(string.charCodeAt(string.length - 1)); + let hasLineBreak = false; + let hasFoldableLine = false; // only checked if shouldTrackWidth + let previousLineBreak = -1; // count the first line correctly + let plain = isPlainSafeFirst(string.charCodeAt(0)) && + !isWhitespace(string.charCodeAt(string.length - 1)); - let char: number, i: number; + let char: number; + let i: number; if (singleLineOnly) { // Case: no block styles. // Check for disallowed characters to rule out plain and single. @@ -300,10 +301,10 @@ function foldLine(line: string, width: number): string { const breakRe = / [^ ]/g; // note: the match index will always be <= length-2. let match; // start is an inclusive index. end, curr, and next are exclusive. - let start = 0, - end, - curr = 0, - next = 0; + let start = 0; + let end; + let curr = 0; + let next = 0; let result = ""; // Invariants: 0 <= start <= length-1. @@ -365,8 +366,8 @@ function foldString(string: string, width: number): string { let match; // tslint:disable-next-line:no-conditional-assignment while ((match = lineRe.exec(string))) { - const prefix = match[1], - line = match[2] || ""; + const prefix = match[1]; + const line = match[2] || ""; moreIndented = line[0] === " "; result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + @@ -380,7 +381,8 @@ function foldString(string: string, width: number): string { // Escapes a double-quoted string. function escapeString(string: string): string { let result = ""; - let char, nextChar; + let char; + let nextChar; let escapeSeq; for (let i = 0; i < string.length; i++) { @@ -508,7 +510,7 @@ function writeFlowSequence( let _result = ""; const _tag = state.tag; - for (let index = 0, length = object.length; index < length; index += 1) { + for (let index = 0; index < object.length; index += 1) { // Write only valid elements. if (writeNode(state, level, object[index], false, false)) { if (index !== 0) _result += `,${!state.condenseFlow ? " " : ""}`; @@ -529,7 +531,7 @@ function writeBlockSequence( let _result = ""; const _tag = state.tag; - for (let index = 0, length = object.length; index < length; index += 1) { + for (let index = 0; index < object.length; index += 1) { // Write only valid elements. if (writeNode(state, level + 1, object[index], true, true)) { if (!compact || index !== 0) { @@ -556,8 +558,8 @@ function writeFlowMapping( object: Any, ) { let _result = ""; - const _tag = state.tag, - objectKeyList = Object.keys(object); + const _tag = state.tag; + const objectKeyList = Object.keys(object); for (const [index, objectKey] of objectKeyList.entries()) { let pairBuffer = state.condenseFlow ? '"' : ""; @@ -596,8 +598,8 @@ function writeBlockMapping( object: Any, compact = false, ) { - const _tag = state.tag, - objectKeyList = Object.keys(object); + const _tag = state.tag; + const objectKeyList = Object.keys(object); let _result = ""; // Allow sorting keys so that the output file is deterministic @@ -810,7 +812,7 @@ function inspectNode( objects.push(object); if (Array.isArray(object)) { - for (let idx = 0, length = object.length; idx < length; idx += 1) { + for (let idx = 0; idx < object.length; idx += 1) { inspectNode(object[idx], objects, duplicatesIndexes); } } else { @@ -826,8 +828,8 @@ function getDuplicateReferences( object: Record, state: DumperState, ) { - const objects: Any[] = [], - duplicatesIndexes: number[] = []; + const objects: Any[] = []; + const duplicatesIndexes: number[] = []; inspectNode(object, objects, duplicatesIndexes); diff --git a/yaml/_loader/loader.ts b/yaml/_loader/loader.ts index eb7058f98..cba2030ac 100644 --- a/yaml/_loader/loader.ts +++ b/yaml/_loader/loader.ts @@ -268,8 +268,8 @@ function captureSegment( if (checkJson) { for ( - let position = 0, length = result.length; - position < length; + let position = 0; + position < result.length; position++ ) { const character = result.charCodeAt(position); @@ -329,7 +329,7 @@ function storeMappingPair( if (Array.isArray(keyNode)) { keyNode = Array.prototype.slice.call(keyNode); - for (let index = 0, quantity = keyNode.length; index < quantity; index++) { + for (let index = 0; index < keyNode.length; index++) { if (Array.isArray(keyNode[index])) { return throwError(state, "nested arrays are not supported inside keys"); } @@ -359,8 +359,8 @@ function storeMappingPair( if (keyTag === "tag:yaml.org,2002:merge") { if (Array.isArray(valueNode)) { for ( - let index = 0, quantity = valueNode.length; - index < quantity; + let index = 0; + index < valueNode.length; index++ ) { mergeMappings(state, result, valueNode[index], overridableKeys); @@ -413,8 +413,8 @@ function skipSeparationSpace( allowComments: boolean, checkIndent: number, ): number { - let lineBreaks = 0, - ch = state.input.charCodeAt(state.position); + let lineBreaks = 0; + let ch = state.input.charCodeAt(state.position); while (ch !== 0) { while (isWhiteSpace(ch)) { @@ -526,8 +526,8 @@ function readPlainScalar( state.kind = "scalar"; state.result = ""; - let captureEnd: number, - captureStart = (captureEnd = state.position); + let captureEnd = state.position; + let captureStart = state.position; let hasPendingContent = false; let line = 0; while (ch !== 0) { @@ -599,7 +599,9 @@ function readSingleQuotedScalar( state: LoaderState, nodeIndent: number, ): boolean { - let ch, captureStart, captureEnd; + let ch; + let captureStart; + let captureEnd; ch = state.input.charCodeAt(state.position); @@ -661,8 +663,8 @@ function readDoubleQuotedScalar( state.kind = "scalar"; state.result = ""; state.position++; - let captureEnd: number, - captureStart = (captureEnd = state.position); + let captureEnd = state.position; + let captureStart = state.position; let tmp: number; while ((ch = state.input.charCodeAt(state.position)) !== 0) { if (ch === 0x22 /* " */) { @@ -752,16 +754,16 @@ function readFlowCollection(state: LoaderState, nodeIndent: number): boolean { ch = state.input.charCodeAt(++state.position); - const tag = state.tag, - anchor = state.anchor; + const tag = state.tag; + const anchor = state.anchor; let readNext = true; - let valueNode, - keyNode, - keyTag: string | null = (keyNode = valueNode = null), - isExplicitPair: boolean, - isPair = (isExplicitPair = false); - let following = 0, - line = 0; + let valueNode = null; + let keyNode = null; + let keyTag: string | null = null; + let isExplicitPair = false; + let isPair = false; + let following = 0; + let line = 0; const overridableKeys: ArrayObject = Object.create(null); while (ch !== 0) { skipSeparationSpace(state, true, nodeIndent); @@ -852,12 +854,12 @@ function readFlowCollection(state: LoaderState, nodeIndent: number): boolean { } function readBlockScalar(state: LoaderState, nodeIndent: number): boolean { - let chomping = CHOMPING_CLIP, - didReadContent = false, - detectedIndent = false, - textIndent = nodeIndent, - emptyLines = 0, - atMoreIndented = false; + let chomping = CHOMPING_CLIP; + let didReadContent = false; + let detectedIndent = false; + let textIndent = nodeIndent; + let emptyLines = 0; + let atMoreIndented = false; let ch = state.input.charCodeAt(state.position); @@ -1007,13 +1009,13 @@ function readBlockScalar(state: LoaderState, nodeIndent: number): boolean { } function readBlockSequence(state: LoaderState, nodeIndent: number): boolean { - let line: number, - following: number, - detected = false, - ch: number; - const tag = state.tag, - anchor = state.anchor, - result: unknown[] = []; + let line: number; + let following: number; + let detected = false; + let ch: number; + const tag = state.tag; + const anchor = state.anchor; + const result: unknown[] = []; if ( state.anchor !== null && @@ -1076,20 +1078,20 @@ function readBlockMapping( nodeIndent: number, flowIndent: number, ): boolean { - const tag = state.tag, - anchor = state.anchor, - result = {}, - overridableKeys = Object.create(null); - let following: number, - allowCompact = false, - line: number, - pos: number, - keyTag = null, - keyNode = null, - valueNode = null, - atExplicitKey = false, - detected = false, - ch: number; + const tag = state.tag; + const anchor = state.anchor; + const result = {}; + const overridableKeys = Object.create(null); + let following: number; + let allowCompact = false; + let line: number; + let pos: number; + let keyTag = null; + let keyNode = null; + let valueNode = null; + let atExplicitKey = false; + let detected = false; + let ch: number; if ( state.anchor !== null && @@ -1270,12 +1272,12 @@ function readBlockMapping( } function readTagProperty(state: LoaderState): boolean { - let position: number, - isVerbatim = false, - isNamed = false, - tagHandle = "", - tagName: string, - ch: number; + let position: number; + let isVerbatim = false; + let isNamed = false; + let tagHandle = ""; + let tagName: string; + let ch: number; ch = state.input.charCodeAt(state.position); @@ -1441,14 +1443,14 @@ function composeNode( allowToSeek: boolean, allowCompact: boolean, ): boolean { - let allowBlockScalars: boolean, - allowBlockCollections: boolean, - indentStatus = 1, // 1: this>parent, 0: this=parent, -1: thisparent, 0: this=parent, -1: this( const documents = loadDocuments(input, options); const iterator = iteratorOrOption; - for (let index = 0, length = documents.length; index < length; index++) { + for (let index = 0; index < documents.length; index++) { iterator(documents[index]); } diff --git a/yaml/_mark.ts b/yaml/_mark.ts index 46528445e..0dab16883 100644 --- a/yaml/_mark.ts +++ b/yaml/_mark.ts @@ -57,8 +57,8 @@ export class Mark { } public toString(compact?: boolean): string { - let snippet, - where = ""; + let snippet; + let where = ""; if (this.name) { where += `in "${this.name}" `;