From d5d7afcd714ca6ce6686f8fd4563cf1f73a8144e Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 8 Apr 2025 19:37:17 +0200 Subject: [PATCH 01/12] initial commit --- _tools/lint_plugin.ts | 51 ++++++++++++++++++++++++++ _tools/lint_plugin_test.ts | 57 ++++++++++++++++++++++++++++++ assert/almost_equals.ts | 1 + assert/array_includes.ts | 1 + assert/equals.ts | 1 + assert/greater.ts | 1 + assert/greater_or_equal.ts | 1 + assert/instance_of.ts | 1 + assert/is_error.ts | 1 + assert/less.ts | 1 + assert/less_or_equal.ts | 1 + assert/match.ts | 1 + assert/not_equals.ts | 1 + assert/not_instance_of.ts | 1 + assert/not_match.ts | 1 + assert/not_strict_equals.ts | 1 + assert/object_match.ts | 1 + assert/rejects.ts | 1 + assert/strict_equals.ts | 1 + assert/string_includes.ts | 1 + assert/throws.ts | 1 + async/_util.ts | 1 + async/pool.ts | 1 + bytes/copy.ts | 1 + bytes/includes_needle.ts | 1 + bytes/index_of_needle.ts | 1 + bytes/last_index_of_needle.ts | 1 + cbor/_common_encode.ts | 1 + collections/reduce_groups.ts | 1 + collections/running_reduce.ts | 1 + csv/_io.ts | 4 +++ encoding/_common16.ts | 2 ++ encoding/_common32.ts | 2 ++ encoding/_common64.ts | 2 ++ encoding/base64.ts | 4 ++- encoding/base64url.ts | 4 ++- encoding/unstable_base32.ts | 1 + encoding/unstable_base64.ts | 6 +++- encoding/unstable_base64_stream.ts | 24 +++++++------ encoding/varint.ts | 1 + expect/_assert_is_error.ts | 1 + expect/_matchers.ts | 4 +++ expect/_utils.ts | 2 ++ fs/_is_subdir.ts | 1 + fs/unstable_chown.ts | 2 ++ fs/unstable_utime.ts | 2 ++ http/cookie.ts | 1 + internal/diff.ts | 2 ++ json/_test_utils.ts | 2 ++ path/_common/basename.ts | 1 + path/_common/glob_to_reg_exp.ts | 1 + path/_common/normalize_string.ts | 1 + streams/_test_utils.ts | 1 + streams/to_transform_stream.ts | 1 + testing/mock.ts | 5 +++ testing/snapshot.ts | 1 + testing/unstable_stub.ts | 1 + toml/_parser.ts | 1 + webgpu/create_capture.ts | 1 + webgpu/row_padding.ts | 1 + webgpu/texture_with_data.ts | 1 + 61 files changed, 206 insertions(+), 13 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index c34b2a275888..85e1c86416ae 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -38,5 +38,56 @@ export default { }; }, }, + // https://docs.deno.com/runtime/contributing/style_guide/#prefer-%23-over-private-keyword + "exported-function-args-maximum": { + create(context) { + return { + ExportNamedDeclaration(node) { + const declaration = node.declaration; + if (declaration?.type !== "FunctionDeclaration") return; + const params = declaration.params; + const id = declaration.id; + switch (params.length) { + case 0: + case 1: + case 2: + break; + case 3: { + const param = params.at(-1)!; + switch (param.type) { + case "Identifier": + if (param.name === "options") return; + break; + case "AssignmentPattern": { + const left = param.left; + if (left.type == "Identifier" && left.name === "options") { + return; + } + break; + } + } + + return context.report({ + node: id ?? declaration, + message: + "Third argument of export function is not an options object.", + hint: + "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", + }); + } + + default: + context.report({ + node: id ?? declaration, + message: "Exported function has more than three arguments.", + hint: + "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", + }); + break; + } + }, + }; + }, + }, }, } satisfies Deno.lint.Plugin; diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 9915a65bb186..9f41fef60d74 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -55,3 +55,60 @@ class MyClass { }], ); }); + +Deno.test("deno-style-guide/exported-function-args-maximum", { + ignore: !Deno.version.deno.startsWith("2"), +}, () => { + // Good + assertLintPluginDiagnostics( + ` +function foo() { +} +function foo(bar: unknown) { +} +function foo(bar: unknown, baz: unknown) { +} +function foo(bar: unknown, baz: unknown, options: Record) { +} +function foo(bar: unknown, baz: unknown, bat: unknown, bay: unknown) { +} +export function foo() { +} +export function foo(bar: unknown) { +} +export function foo(bar: unknown, baz: unknown) { +} +export function foo(bar: unknown, baz: unknown, options: Record) { +} + `, + [], + ); + + // Bad + assertLintPluginDiagnostics( + ` +export function foo(bar: unknown, baz: unknown, bat: unknown) { +} +export function foo(bar: unknown, baz: unknown, bat: unknown, options: Record) { +} +`, + [ + { + fix: [], + hint: + "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", + id: "deno-style-guide/exported-function-args-maximum", + message: "Third argument of export function is not an options object.", + range: [8, 66], + }, + { + fix: [], + hint: + "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", + id: "deno-style-guide/exported-function-args-maximum", + message: "Exported function has more than three arguments.", + range: [74, 166], + }, + ], + ); +}); diff --git a/assert/almost_equals.ts b/assert/almost_equals.ts index 8e1c38c96792..423969f4f4f8 100644 --- a/assert/almost_equals.ts +++ b/assert/almost_equals.ts @@ -29,6 +29,7 @@ import { AssertionError } from "./assertion_error.ts"; * default is one hundred thousandth of a percent of the expected value. * @param msg The optional message to include in the error. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertAlmostEquals( actual: number, expected: number, diff --git a/assert/array_includes.ts b/assert/array_includes.ts index bcc14fefccd8..ea8fbe0ad079 100644 --- a/assert/array_includes.ts +++ b/assert/array_includes.ts @@ -27,6 +27,7 @@ export type ArrayLikeArg = ArrayLike & object; * @param expected The array-like object to check for. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertArrayIncludes( actual: ArrayLikeArg, expected: ArrayLikeArg, diff --git a/assert/equals.ts b/assert/equals.ts index f0e355590a5b..b34e218916fd 100644 --- a/assert/equals.ts +++ b/assert/equals.ts @@ -41,6 +41,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertEquals( actual: T, expected: T, diff --git a/assert/greater.ts b/assert/greater.ts index d3d8aa73463c..fb5f76816e75 100644 --- a/assert/greater.ts +++ b/assert/greater.ts @@ -21,6 +21,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertGreater(actual: T, expected: T, msg?: string) { if (actual > expected) return; diff --git a/assert/greater_or_equal.ts b/assert/greater_or_equal.ts index dbd8642045b4..1fd891bd89bf 100644 --- a/assert/greater_or_equal.ts +++ b/assert/greater_or_equal.ts @@ -21,6 +21,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertGreaterOrEqual( actual: T, expected: T, diff --git a/assert/instance_of.ts b/assert/instance_of.ts index 5856df063200..a208b3986055 100644 --- a/assert/instance_of.ts +++ b/assert/instance_of.ts @@ -25,6 +25,7 @@ export type GetConstructorType = InstanceType; * @param expectedType The expected class constructor. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertInstanceOf< // deno-lint-ignore no-explicit-any T extends abstract new (...args: any[]) => any, diff --git a/assert/is_error.ts b/assert/is_error.ts index 22dab3f30904..69543ec8902e 100644 --- a/assert/is_error.ts +++ b/assert/is_error.ts @@ -26,6 +26,7 @@ import { stripAnsiCode } from "@std/internal/styles"; * @param msgMatches The optional string or RegExp to assert in the error message. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertIsError( error: unknown, // deno-lint-ignore no-explicit-any diff --git a/assert/less.ts b/assert/less.ts index 4436bd2df1e1..cc47f332b4a3 100644 --- a/assert/less.ts +++ b/assert/less.ts @@ -20,6 +20,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertLess(actual: T, expected: T, msg?: string) { if (actual < expected) return; diff --git a/assert/less_or_equal.ts b/assert/less_or_equal.ts index 6569eb62c34e..bcdd369dcb67 100644 --- a/assert/less_or_equal.ts +++ b/assert/less_or_equal.ts @@ -21,6 +21,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertLessOrEqual( actual: T, expected: T, diff --git a/assert/match.ts b/assert/match.ts index 8c49ffa7dc54..ee41ea2edd23 100644 --- a/assert/match.ts +++ b/assert/match.ts @@ -18,6 +18,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected pattern to match. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertMatch( actual: string, expected: RegExp, diff --git a/assert/not_equals.ts b/assert/not_equals.ts index 70bdab6033a4..009605b0079c 100644 --- a/assert/not_equals.ts +++ b/assert/not_equals.ts @@ -24,6 +24,7 @@ import { format } from "@std/internal/format"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotEquals(actual: T, expected: T, msg?: string) { if (!equal(actual, expected)) { return; diff --git a/assert/not_instance_of.ts b/assert/not_instance_of.ts index 01bfdde07d49..ab46daef2d54 100644 --- a/assert/not_instance_of.ts +++ b/assert/not_instance_of.ts @@ -20,6 +20,7 @@ import { assertFalse } from "./false.ts"; * @param unexpectedType The class constructor to check against. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotInstanceOf( actual: A, // deno-lint-ignore no-explicit-any diff --git a/assert/not_match.ts b/assert/not_match.ts index 533ed170b735..8086ab25eb43 100644 --- a/assert/not_match.ts +++ b/assert/not_match.ts @@ -18,6 +18,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to not match. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotMatch( actual: string, expected: RegExp, diff --git a/assert/not_strict_equals.ts b/assert/not_strict_equals.ts index 2c62099c59d9..a670cc2a4131 100644 --- a/assert/not_strict_equals.ts +++ b/assert/not_strict_equals.ts @@ -24,6 +24,7 @@ import { format } from "@std/internal/format"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotStrictEquals( actual: T, expected: T, diff --git a/assert/object_match.ts b/assert/object_match.ts index ab30fee0fba5..d40c239d023d 100644 --- a/assert/object_match.ts +++ b/assert/object_match.ts @@ -29,6 +29,7 @@ import { assertEquals } from "./equals.ts"; * @param expected The expected value to match. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertObjectMatch( // deno-lint-ignore no-explicit-any actual: Record, diff --git a/assert/rejects.ts b/assert/rejects.ts index b61aa317d762..07334f92353c 100644 --- a/assert/rejects.ts +++ b/assert/rejects.ts @@ -53,6 +53,7 @@ export function assertRejects( msgIncludes?: string, msg?: string, ): Promise; +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertRejects( fn: () => PromiseLike, errorClassOrMsg?: diff --git a/assert/strict_equals.ts b/assert/strict_equals.ts index 197a5c708d88..4459139b9c7a 100644 --- a/assert/strict_equals.ts +++ b/assert/strict_equals.ts @@ -29,6 +29,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertStrictEquals( actual: unknown, expected: T, diff --git a/assert/string_includes.ts b/assert/string_includes.ts index 9791d460b7c8..7c9b511438e7 100644 --- a/assert/string_includes.ts +++ b/assert/string_includes.ts @@ -18,6 +18,7 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected string to check for inclusion. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertStringIncludes( actual: string, expected: string, diff --git a/assert/throws.ts b/assert/throws.ts index 392ff912c49f..3afeb4d59b3c 100644 --- a/assert/throws.ts +++ b/assert/throws.ts @@ -56,6 +56,7 @@ export function assertThrows( msgIncludes?: string, msg?: string, ): E; +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertThrows( fn: () => unknown, errorClassOrMsg?: diff --git a/async/_util.ts b/async/_util.ts index f1a461633800..80c19bf4bddf 100644 --- a/async/_util.ts +++ b/async/_util.ts @@ -1,6 +1,7 @@ // Copyright 2018-2025 the Deno authors. MIT license. // This module is browser compatible. +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function exponentialBackoffWithJitter( cap: number, base: number, diff --git a/async/pool.ts b/async/pool.ts index d8a9f853b29a..25f092ee3e1e 100644 --- a/async/pool.ts +++ b/async/pool.ts @@ -36,6 +36,7 @@ const ERROR_WHILE_MAPPING_MESSAGE = * @param iteratorFn The function to call for every item of the array. * @returns The async iterator with the transformed values. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function pooledMap( poolLimit: number, array: Iterable | AsyncIterable, diff --git a/bytes/copy.ts b/bytes/copy.ts index 1d85b762e711..df7596d44f51 100644 --- a/bytes/copy.ts +++ b/bytes/copy.ts @@ -40,6 +40,7 @@ * Defining an offset will start copying at the specified index in the * destination array. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function copy(src: Uint8Array, dst: Uint8Array, offset = 0): number { offset = Math.max(0, Math.min(offset, dst.byteLength)); const dstBytesAvailable = dst.byteLength - offset; diff --git a/bytes/includes_needle.ts b/bytes/includes_needle.ts index 90ecb5aaf4fb..67b321f59da2 100644 --- a/bytes/includes_needle.ts +++ b/bytes/includes_needle.ts @@ -39,6 +39,7 @@ import { indexOfNeedle } from "./index_of_needle.ts"; * ``` * The search will start at the specified index in the source array. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function includesNeedle( source: Uint8Array, needle: Uint8Array, diff --git a/bytes/index_of_needle.ts b/bytes/index_of_needle.ts index 988965f9c39f..b89c1766d31e 100644 --- a/bytes/index_of_needle.ts +++ b/bytes/index_of_needle.ts @@ -44,6 +44,7 @@ * Defining a start index will begin the search at the specified index in the * source array. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function indexOfNeedle( source: Uint8Array, needle: Uint8Array, diff --git a/bytes/last_index_of_needle.ts b/bytes/last_index_of_needle.ts index 1b70c172d3ca..0f85133b3c61 100644 --- a/bytes/last_index_of_needle.ts +++ b/bytes/last_index_of_needle.ts @@ -41,6 +41,7 @@ * Defining a start index will begin the search at the specified index in the * source array. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function lastIndexOfNeedle( source: Uint8Array, needle: Uint8Array, diff --git a/cbor/_common_encode.ts b/cbor/_common_encode.ts index f05c04ef4138..a6467a807e24 100644 --- a/cbor/_common_encode.ts +++ b/cbor/_common_encode.ts @@ -60,6 +60,7 @@ export function calcEncodingSize(x: CborType): number { return size + calcHeaderSize(pairs); } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( input: CborType, output: Uint8Array, diff --git a/collections/reduce_groups.ts b/collections/reduce_groups.ts index 849c55395a7e..2df6cdb2b3f7 100644 --- a/collections/reduce_groups.ts +++ b/collections/reduce_groups.ts @@ -36,6 +36,7 @@ import { mapValues } from "./map_values.ts"; * }); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function reduceGroups( record: Readonly>>, reducer: (accumulator: A, current: T) => A, diff --git a/collections/running_reduce.ts b/collections/running_reduce.ts index 121e196daa71..ce1445f1b77a 100644 --- a/collections/running_reduce.ts +++ b/collections/running_reduce.ts @@ -26,6 +26,7 @@ * assertEquals(sumSteps, [1, 3, 6, 10, 15]); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function runningReduce( array: readonly T[], reducer: (accumulator: O, current: T, currentIndex: number) => O, diff --git a/csv/_io.ts b/csv/_io.ts index dd164927ec86..cb9a39ab7dcd 100644 --- a/csv/_io.ts +++ b/csv/_io.ts @@ -56,6 +56,7 @@ export interface LineReader { isEOF(): boolean; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function parseRecord( fullLine: string, reader: LineReader, @@ -201,6 +202,7 @@ export async function parseRecord( return result; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createBareQuoteErrorMessage( zeroBasedRecordStartLine: number, zeroBasedLine: number, @@ -212,6 +214,7 @@ export function createBareQuoteErrorMessage( zeroBasedColumn + 1 }: bare " in non-quoted-field`; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createQuoteErrorMessage( zeroBasedRecordStartLine: number, zeroBasedLine: number, @@ -224,6 +227,7 @@ export function createQuoteErrorMessage( }: extraneous or missing " in quoted-field`; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function convertRowToObject( row: readonly string[], headers: readonly string[], diff --git a/encoding/_common16.ts b/encoding/_common16.ts index af0e594c7390..523d42fced19 100644 --- a/encoding/_common16.ts +++ b/encoding/_common16.ts @@ -29,6 +29,7 @@ export function calcSizeHex(originalSize: number): number { return originalSize * 2; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( buffer: Uint8Array_, i: number, @@ -43,6 +44,7 @@ export function encode( return o; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function decode( buffer: Uint8Array_, i: number, diff --git a/encoding/_common32.ts b/encoding/_common32.ts index 1ec1201cdca6..147ca6c428bf 100644 --- a/encoding/_common32.ts +++ b/encoding/_common32.ts @@ -45,6 +45,7 @@ export function calcSizeBase32(rawSize: number): number { return ((rawSize + 4) / 5 | 0) * 8; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( buffer: Uint8Array_, i: number, @@ -120,6 +121,7 @@ export function encode( return o; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function decode( buffer: Uint8Array_, i: number, diff --git a/encoding/_common64.ts b/encoding/_common64.ts index c5756092c8eb..50a8d2d626c8 100644 --- a/encoding/_common64.ts +++ b/encoding/_common64.ts @@ -43,6 +43,7 @@ export function calcSizeBase64(originalSize: number): number { return ((originalSize + 2) / 3 | 0) * 4; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( buffer: Uint8Array_, i: number, @@ -79,6 +80,7 @@ export function encode( return o; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function decode( buffer: Uint8Array_, i: number, diff --git a/encoding/base64.ts b/encoding/base64.ts index 9101750399a7..0f07b8dc2d4c 100644 --- a/encoding/base64.ts +++ b/encoding/base64.ts @@ -85,5 +85,7 @@ export function decodeBase64(b64: string): Uint8Array_ { const output = new TextEncoder().encode(b64) as Uint8Array_; // deno-lint-ignore no-explicit-any return new Uint8Array((output.buffer as any) - .transfer(decode(output, 0, 0, rAlphabet, padding))); + .transfer( + decode({ buffer: output, i: 0, o: 0, alphabet: rAlphabet, padding }), + )); } diff --git a/encoding/base64url.ts b/encoding/base64url.ts index 0a19582e66f3..4475ad62682c 100644 --- a/encoding/base64url.ts +++ b/encoding/base64url.ts @@ -78,5 +78,7 @@ export function decodeBase64Url(b64url: string): Uint8Array_ { const output = new TextEncoder().encode(b64url) as Uint8Array_; // deno-lint-ignore no-explicit-any return new Uint8Array((output.buffer as any) - .transfer(decode(output, 0, 0, rAlphabet, padding))); + .transfer( + decode({ buffer: output, i: 0, o: 0, alphabet: rAlphabet, padding }), + )); } diff --git a/encoding/unstable_base32.ts b/encoding/unstable_base32.ts index cdae578e6328..f81c9ae8b80a 100644 --- a/encoding/unstable_base32.ts +++ b/encoding/unstable_base32.ts @@ -122,6 +122,7 @@ export function encodeBase32( * ); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encodeIntoBase32( input: string | Uint8Array_ | ArrayBuffer, output: Uint8Array_, diff --git a/encoding/unstable_base64.ts b/encoding/unstable_base64.ts index d7deb2eaca0e..1289b6795afe 100644 --- a/encoding/unstable_base64.ts +++ b/encoding/unstable_base64.ts @@ -120,6 +120,7 @@ export function encodeBase64( * ); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encodeIntoBase64( input: string | Uint8Array_ | ArrayBuffer, output: Uint8Array_, @@ -178,5 +179,8 @@ export function decodeBase64( if (typeof input === "string") { input = new TextEncoder().encode(input) as Uint8Array_; } - return input.subarray(0, decode(input, 0, 0, rAlphabet[format], padding)); + return input.subarray( + 0, + decode({ buffer: input, i: 0, o: 0, alphabet: rAlphabet[format], padding }), + ); } diff --git a/encoding/unstable_base64_stream.ts b/encoding/unstable_base64_stream.ts index 081beda3a0f9..87ccb398dca2 100644 --- a/encoding/unstable_base64_stream.ts +++ b/encoding/unstable_base64_stream.ts @@ -179,22 +179,26 @@ export class Base64DecoderStream remainder = output.length % 4; if (remainder) push.set(output.subarray(-remainder)); const o = decode( - output.subarray(0, -remainder || undefined), - 0, - 0, - abc, - padding, + { + buffer: output.subarray(0, -remainder || undefined), + i: 0, + o: 0, + alphabet: abc, + padding, + }, ); controller.enqueue(output.subarray(0, o)); }, flush(controller) { if (remainder) { const o = decode( - push.subarray(0, remainder), - 0, - 0, - abc, - padding, + { + buffer: push.subarray(0, remainder), + i: 0, + o: 0, + alphabet: abc, + padding, + }, ); controller.enqueue(push.subarray(0, o)); } diff --git a/encoding/varint.ts b/encoding/varint.ts index c20f1242c80c..f8069f639fcb 100644 --- a/encoding/varint.ts +++ b/encoding/varint.ts @@ -215,6 +215,7 @@ export function decodeVarint32(buf: Uint8Array, offset = 0): [number, number] { * assertEquals(encodeVarint(42n, buf), [new Uint8Array([42]), 1]); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encodeVarint( num: bigint | number, buf: Uint8Array = new Uint8Array(MaxVarintLen64), diff --git a/expect/_assert_is_error.ts b/expect/_assert_is_error.ts index f3abdce84eaf..4f73fd69cee7 100644 --- a/expect/_assert_is_error.ts +++ b/expect/_assert_is_error.ts @@ -15,6 +15,7 @@ import { stripAnsiCode } from "@std/internal/styles"; * @param msgMatches The optional string or RegExp to assert in the error message. * @param msg The optional message to display if the assertion fails. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertIsError( error: unknown, // deno-lint-ignore no-explicit-any diff --git a/expect/_matchers.ts b/expect/_matchers.ts index b03da0d2f29e..a30d25379b79 100644 --- a/expect/_matchers.ts +++ b/expect/_matchers.ts @@ -75,6 +75,7 @@ export function toStrictEqual( } } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toBeCloseTo( context: MatcherContext, expected: number, @@ -374,6 +375,7 @@ export function toHaveLength( } } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toHaveProperty( context: MatcherContext, propName: string | string[], @@ -741,6 +743,7 @@ export function toHaveBeenLastCalledWith( } } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toHaveBeenNthCalledWith( context: MatcherContext, nth: number, @@ -924,6 +927,7 @@ export function toHaveLastReturnedWith( } } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toHaveNthReturnedWith( context: MatcherContext, nth: number, diff --git a/expect/_utils.ts b/expect/_utils.ts index bdc5974d7ada..b73b407f5706 100644 --- a/expect/_utils.ts +++ b/expect/_utils.ts @@ -85,6 +85,7 @@ function entries(obj: any) { } // Ported from https://github.com/jestjs/jest/blob/442c7f692e3a92f14a2fb56c1737b26fc663a0ef/packages/expect-utils/src/utils.ts#L173 +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function iterableEquality( // deno-lint-ignore no-explicit-any a: any, @@ -235,6 +236,7 @@ export function iterableEquality( } // Ported from https://github.com/jestjs/jest/blob/442c7f692e3a92f14a2fb56c1737b26fc663a0ef/packages/expect-utils/src/utils.ts#L341 +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function subsetEquality( object: unknown, subset: unknown, diff --git a/fs/_is_subdir.ts b/fs/_is_subdir.ts index 4fb1cd74f7fa..1bf7be9685d7 100644 --- a/fs/_is_subdir.ts +++ b/fs/_is_subdir.ts @@ -15,6 +15,7 @@ import { toPathString } from "./_to_path_string.ts"; * * @returns `true` if `src` is a sub-directory of `dest`, `false` otherwise. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function isSubdir( src: string | URL, dest: string | URL, diff --git a/fs/unstable_chown.ts b/fs/unstable_chown.ts index 1b2e31032bf3..fb8e11b1b329 100644 --- a/fs/unstable_chown.ts +++ b/fs/unstable_chown.ts @@ -24,6 +24,7 @@ import { mapError } from "./_map_error.ts"; * @param uid The user id (UID) of the new owner, or `null` for no change. * @param gid The group id (GID) of the new owner, or `null` for no change. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function chown( path: string | URL, uid: number | null, @@ -61,6 +62,7 @@ export async function chown( * @param uid The user id (UID) of the new owner, or `null` for no change. * @param gid The group id (GID) of the new owner, or `null` for no change. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function chownSync( path: string | URL, uid: number | null, diff --git a/fs/unstable_utime.ts b/fs/unstable_utime.ts index 47bb01505964..dce063336ff4 100644 --- a/fs/unstable_utime.ts +++ b/fs/unstable_utime.ts @@ -32,6 +32,7 @@ import { mapError } from "./_map_error.ts"; * @param atime The new access time * @param mtime The new modification time */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function utime( path: string | URL, atime: number | Date, @@ -78,6 +79,7 @@ export async function utime( * @param atime The new access time * @param mtime The new modification time */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function utimeSync( path: string | URL, atime: number | Date, diff --git a/http/cookie.ts b/http/cookie.ts index 93b0bdc4b17e..f5cd602dc99c 100644 --- a/http/cookie.ts +++ b/http/cookie.ts @@ -324,6 +324,7 @@ export function setCookie(headers: Headers, cookie: Cookie) { * @param name Name of cookie * @param attributes Additional cookie attributes */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function deleteCookie( headers: Headers, name: string, diff --git a/internal/diff.ts b/internal/diff.ts index e6c530550b0f..f77e74ceee46 100644 --- a/internal/diff.ts +++ b/internal/diff.ts @@ -108,6 +108,7 @@ export function assertFp(value: unknown): asserts value is FarthestPoint { * ); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function backTrace( A: T[], B: T[], @@ -184,6 +185,7 @@ export function backTrace( * ); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createFp( k: number, M: number, diff --git a/json/_test_utils.ts b/json/_test_utils.ts index 9f10fa4c8d77..a17d4050b839 100644 --- a/json/_test_utils.ts +++ b/json/_test_utils.ts @@ -3,6 +3,7 @@ import { assertEquals, assertRejects } from "@std/assert"; import type { ConcatenatedJsonParseStream } from "./concatenated_json_parse_stream.ts"; import type { JsonParseStream } from "./parse_stream.ts"; +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertValidParse( transform: typeof ConcatenatedJsonParseStream | typeof JsonParseStream, chunks: string[], @@ -14,6 +15,7 @@ export async function assertValidParse( assertEquals(res, expect); } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertInvalidParse( transform: typeof ConcatenatedJsonParseStream | typeof JsonParseStream, chunks: string[], diff --git a/path/_common/basename.ts b/path/_common/basename.ts index dec849d53497..9604fa77d891 100644 --- a/path/_common/basename.ts +++ b/path/_common/basename.ts @@ -19,6 +19,7 @@ export function stripSuffix(name: string, suffix: string): string { return name.slice(0, -suffix.length); } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function lastPathSegment( path: string, isSep: (char: number) => boolean, diff --git a/path/_common/glob_to_reg_exp.ts b/path/_common/glob_to_reg_exp.ts index d5b45da72bf6..1a5d455f0e76 100644 --- a/path/_common/glob_to_reg_exp.ts +++ b/path/_common/glob_to_reg_exp.ts @@ -58,6 +58,7 @@ export interface GlobConstants { escapePrefix: string; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function _globToRegExp( c: GlobConstants, glob: string, diff --git a/path/_common/normalize_string.ts b/path/_common/normalize_string.ts index dbcf59029bc3..50903ef3d98c 100644 --- a/path/_common/normalize_string.ts +++ b/path/_common/normalize_string.ts @@ -6,6 +6,7 @@ import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./constants.ts"; // Resolves . and .. elements in a path with directory names +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function normalizeString( path: string, allowAboveRoot: boolean, diff --git a/streams/_test_utils.ts b/streams/_test_utils.ts index 63e57859190d..35ae184b95d9 100644 --- a/streams/_test_utils.ts +++ b/streams/_test_utils.ts @@ -8,6 +8,7 @@ import { assert, assertEquals } from "@std/assert"; * @param inputs Source input data * @param outputs Expected output data */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function testTransformStream( transform: TransformStream, inputs: Iterable | AsyncIterable, diff --git a/streams/to_transform_stream.ts b/streams/to_transform_stream.ts index 85a0d0d7b4ca..aca415bb4f7a 100644 --- a/streams/to_transform_stream.ts +++ b/streams/to_transform_stream.ts @@ -60,6 +60,7 @@ * ); * ``` */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toTransformStream( transformer: (src: ReadableStream) => Iterable | AsyncIterable, writableStrategy?: QueuingStrategy, diff --git a/testing/mock.ts b/testing/mock.ts index 049c2c16bb68..1e87a501ed7a 100644 --- a/testing/mock.ts +++ b/testing/mock.ts @@ -1052,6 +1052,7 @@ export function stub< ...args: GetParametersFromProp ) => GetReturnFromProp, ): Stub, GetReturnFromProp>; +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function stub< Self, Args extends unknown[], @@ -1256,6 +1257,7 @@ function getSpyCall< * @param callIndex The index of the call to check * @param expected The expected spy call. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertSpyCall< Self, Args extends unknown[], @@ -1355,6 +1357,7 @@ export function assertSpyCall< * @param callIndex The index of the call to check * @param expected The expected spy call. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertSpyCallAsync< Self, Args extends unknown[], @@ -1456,6 +1459,7 @@ export async function assertSpyCallAsync< * @param expected The expected argument. * @returns The actual argument. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertSpyCallArg< Self, Args extends unknown[], @@ -1590,6 +1594,7 @@ export function assertSpyCallArgs< argsEnd: number, expected: ExpectedArgs, ): ExpectedArgs; +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertSpyCallArgs< ExpectedArgs extends unknown[], Args extends unknown[], diff --git a/testing/snapshot.ts b/testing/snapshot.ts index c70f97909523..c45142806e4b 100644 --- a/testing/snapshot.ts +++ b/testing/snapshot.ts @@ -572,6 +572,7 @@ export async function assertSnapshot( actual: T, message?: string, ): Promise; +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertSnapshot( context: Deno.TestContext, actual: unknown, diff --git a/testing/unstable_stub.ts b/testing/unstable_stub.ts index 93800f805e7a..2080dfb801e4 100644 --- a/testing/unstable_stub.ts +++ b/testing/unstable_stub.ts @@ -149,6 +149,7 @@ export function stub( GetReturnFromProp >; }; +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function stub( self: Self, property: keyof Self, diff --git a/toml/_parser.ts b/toml/_parser.ts index 0137f58a93c8..98b618bc25b4 100644 --- a/toml/_parser.ts +++ b/toml/_parser.ts @@ -134,6 +134,7 @@ function failure(): Failure { return { ok: false }; } +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function unflat( keys: string[], values: unknown = {}, diff --git a/webgpu/create_capture.ts b/webgpu/create_capture.ts index 120f876ea3c5..862289306d50 100644 --- a/webgpu/create_capture.ts +++ b/webgpu/create_capture.ts @@ -70,6 +70,7 @@ export interface CreateCapture { * @param height The height of the capture texture. * @returns The texture to render to and buffer to read from. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createCapture( device: GPUDevice, width: number, diff --git a/webgpu/row_padding.ts b/webgpu/row_padding.ts index 7cc681780834..b1d40aee7eef 100644 --- a/webgpu/row_padding.ts +++ b/webgpu/row_padding.ts @@ -70,6 +70,7 @@ export function getRowPadding(width: number): Padding { * @param height The height of the output buffer. * @returns The resliced buffer. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function resliceBufferWithPadding( buffer: Uint8Array, width: number, diff --git a/webgpu/texture_with_data.ts b/webgpu/texture_with_data.ts index 5a3f094080e5..0f7a859bbdd7 100644 --- a/webgpu/texture_with_data.ts +++ b/webgpu/texture_with_data.ts @@ -120,6 +120,7 @@ function textureMipLevelSize( * @param data The data to write to the texture. * @returns The newly created texture. */ +// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createTextureWithData( device: GPUDevice, descriptor: GPUTextureDescriptor, From d1a33ef5334618a3e9a719d643e9aa0e626ed9f9 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 8 Apr 2025 19:43:01 +0200 Subject: [PATCH 02/12] update --- _tools/lint_plugin_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 9f41fef60d74..9168d340e490 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -99,7 +99,7 @@ export function foo(bar: unknown, baz: unknown, bat: unknown, options: Record Date: Tue, 8 Apr 2025 19:45:02 +0200 Subject: [PATCH 03/12] revert changes --- encoding/base64.ts | 4 +--- encoding/base64url.ts | 4 +--- encoding/unstable_base64.ts | 5 +---- encoding/unstable_base64_stream.ts | 24 ++++++++++-------------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/encoding/base64.ts b/encoding/base64.ts index 0f07b8dc2d4c..9101750399a7 100644 --- a/encoding/base64.ts +++ b/encoding/base64.ts @@ -85,7 +85,5 @@ export function decodeBase64(b64: string): Uint8Array_ { const output = new TextEncoder().encode(b64) as Uint8Array_; // deno-lint-ignore no-explicit-any return new Uint8Array((output.buffer as any) - .transfer( - decode({ buffer: output, i: 0, o: 0, alphabet: rAlphabet, padding }), - )); + .transfer(decode(output, 0, 0, rAlphabet, padding))); } diff --git a/encoding/base64url.ts b/encoding/base64url.ts index 4475ad62682c..0a19582e66f3 100644 --- a/encoding/base64url.ts +++ b/encoding/base64url.ts @@ -78,7 +78,5 @@ export function decodeBase64Url(b64url: string): Uint8Array_ { const output = new TextEncoder().encode(b64url) as Uint8Array_; // deno-lint-ignore no-explicit-any return new Uint8Array((output.buffer as any) - .transfer( - decode({ buffer: output, i: 0, o: 0, alphabet: rAlphabet, padding }), - )); + .transfer(decode(output, 0, 0, rAlphabet, padding))); } diff --git a/encoding/unstable_base64.ts b/encoding/unstable_base64.ts index 1289b6795afe..a537830b7ea8 100644 --- a/encoding/unstable_base64.ts +++ b/encoding/unstable_base64.ts @@ -179,8 +179,5 @@ export function decodeBase64( if (typeof input === "string") { input = new TextEncoder().encode(input) as Uint8Array_; } - return input.subarray( - 0, - decode({ buffer: input, i: 0, o: 0, alphabet: rAlphabet[format], padding }), - ); + return input.subarray(0, decode(input, 0, 0, rAlphabet[format], padding)); } diff --git a/encoding/unstable_base64_stream.ts b/encoding/unstable_base64_stream.ts index 87ccb398dca2..081beda3a0f9 100644 --- a/encoding/unstable_base64_stream.ts +++ b/encoding/unstable_base64_stream.ts @@ -179,26 +179,22 @@ export class Base64DecoderStream remainder = output.length % 4; if (remainder) push.set(output.subarray(-remainder)); const o = decode( - { - buffer: output.subarray(0, -remainder || undefined), - i: 0, - o: 0, - alphabet: abc, - padding, - }, + output.subarray(0, -remainder || undefined), + 0, + 0, + abc, + padding, ); controller.enqueue(output.subarray(0, o)); }, flush(controller) { if (remainder) { const o = decode( - { - buffer: push.subarray(0, remainder), - i: 0, - o: 0, - alphabet: abc, - padding, - }, + push.subarray(0, remainder), + 0, + 0, + abc, + padding, ); controller.enqueue(push.subarray(0, o)); } From a05e284a21acf85000b2d0ee4d1f866c26f650ce Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 18 Apr 2025 15:23:54 +0200 Subject: [PATCH 04/12] update --- _tools/lint_plugin.ts | 59 ++++++++++++++------------------- path/_common/glob_to_reg_exp.ts | 1 - 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 2a7776c2a232..639b7b0fd93f 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -249,44 +249,33 @@ export default { if (declaration?.type !== "FunctionDeclaration") return; const params = declaration.params; const id = declaration.id; - switch (params.length) { - case 0: - case 1: - case 2: - break; - case 3: { - const param = params.at(-1)!; - switch (param.type) { - case "Identifier": - if (param.name === "options") return; - break; - case "AssignmentPattern": { - const left = param.left; - if (left.type == "Identifier" && left.name === "options") { - return; - } - break; - } - } + if (params.length < 3) return; + if (params.length === 3) { + const param = params.at(-1)!; - return context.report({ - node: id ?? declaration, - message: - "Third argument of export function is not an options object.", - hint: - "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", - }); + switch (param.type) { + case "Identifier": + if (param.name === "options") return; + break; + case "AssignmentPattern": { + if (param.right.type === "ObjectExpression") return; + break; + } } - - default: - context.report({ - node: id ?? declaration, - message: "Exported function has more than three arguments.", - hint: - "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", - }); - break; + return context.report({ + node: id ?? declaration, + message: + "Third argument of export function is not an options object.", + hint: + "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", + }); } + context.report({ + node: id ?? declaration, + message: "Exported function has more than three arguments.", + hint: + "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", + }); }, }; }, diff --git a/path/_common/glob_to_reg_exp.ts b/path/_common/glob_to_reg_exp.ts index 1a5d455f0e76..d5b45da72bf6 100644 --- a/path/_common/glob_to_reg_exp.ts +++ b/path/_common/glob_to_reg_exp.ts @@ -58,7 +58,6 @@ export interface GlobConstants { escapePrefix: string; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function _globToRegExp( c: GlobConstants, glob: string, From d93bcedef264e883354b0651f8a7d1374ebc8e33 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 25 Apr 2025 09:07:51 +0200 Subject: [PATCH 05/12] update --- _tools/lint_plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 5d44fbe92a27..9473ec38e8a9 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -310,7 +310,7 @@ export default { }; }, }, - // https://docs.deno.com/runtime/contributing/style_guide/#prefer-%23-over-private-keyword + // https://docs.deno.com/runtime/contributing/style_guide/#exported-functions%3A-max-2-args%2C-put-the-rest-into-an-options-object "exported-function-args-maximum": { create(context) { return { From facb15394d3878fa6c6de88b5edf332c782b2da6 Mon Sep 17 00:00:00 2001 From: Tim Reichen Date: Sat, 10 May 2025 12:12:55 +0200 Subject: [PATCH 06/12] Update lint_plugin.ts Co-authored-by: Asher Gomez --- _tools/lint_plugin.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 9473ec38e8a9..524f292b7345 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -315,10 +315,8 @@ export default { create(context) { return { ExportNamedDeclaration(node) { - const declaration = node.declaration; - if (declaration?.type !== "FunctionDeclaration") return; - const params = declaration.params; - const id = declaration.id; + if (node.declaration?.type !== "FunctionDeclaration") return; + const { params, id } = node.declaration; if (params.length < 3) return; if (params.length === 3) { const param = params.at(-1)!; From cfd14e51e3c19b2fea2f61b0c111ab48174690ca Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 12 May 2025 16:00:51 +0900 Subject: [PATCH 07/12] reduce false positves --- _tools/lint_plugin.ts | 10 ++++++++++ assert/almost_equals.ts | 1 - assert/array_includes.ts | 1 - assert/equals.ts | 1 - assert/greater.ts | 1 - assert/greater_or_equal.ts | 1 - assert/instance_of.ts | 1 - assert/is_error.ts | 1 - assert/less.ts | 1 - assert/less_or_equal.ts | 1 - assert/match.ts | 1 - assert/not_equals.ts | 1 - assert/not_instance_of.ts | 1 - assert/not_match.ts | 1 - assert/not_strict_equals.ts | 1 - assert/object_match.ts | 1 - assert/rejects.ts | 1 - assert/strict_equals.ts | 1 - assert/string_includes.ts | 1 - assert/throws.ts | 1 - async/_util.ts | 1 - cbor/_common_encode.ts | 1 - csv/_io.ts | 4 ---- encoding/_common16.ts | 2 -- encoding/_common32.ts | 2 -- encoding/_common64.ts | 2 -- expect/_assert_is_error.ts | 1 - expect/_matchers.ts | 4 ---- expect/_utils.ts | 2 -- fs/_is_subdir.ts | 1 - json/_test_utils.ts | 2 -- path/_common/basename.ts | 1 - path/_common/normalize_string.ts | 1 - streams/_test_utils.ts | 1 - 34 files changed, 10 insertions(+), 44 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 524f292b7345..3eeac8b01db5 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -7,6 +7,7 @@ */ import { toCamelCase, toPascalCase } from "@std/text"; +import { toFileUrl } from "@std/path/to-file-url"; const PASCAL_CASE_REGEXP = /^_?(?:[A-Z][a-z0-9]*)*_?$/; const UPPER_CASE_ONLY = /^_?[A-Z]{2,}$/; @@ -313,6 +314,15 @@ export default { // https://docs.deno.com/runtime/contributing/style_guide/#exported-functions%3A-max-2-args%2C-put-the-rest-into-an-options-object "exported-function-args-maximum": { create(context) { + const url = toFileUrl(context.filename); + if (url.href.includes("/assert/")) { + // assert module generally don't follow this rule + return {}; + } + if (url.href.includes("/_")) { + // exports from private utils don't need to follow this rule + return {}; + } return { ExportNamedDeclaration(node) { if (node.declaration?.type !== "FunctionDeclaration") return; diff --git a/assert/almost_equals.ts b/assert/almost_equals.ts index 423969f4f4f8..8e1c38c96792 100644 --- a/assert/almost_equals.ts +++ b/assert/almost_equals.ts @@ -29,7 +29,6 @@ import { AssertionError } from "./assertion_error.ts"; * default is one hundred thousandth of a percent of the expected value. * @param msg The optional message to include in the error. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertAlmostEquals( actual: number, expected: number, diff --git a/assert/array_includes.ts b/assert/array_includes.ts index ea8fbe0ad079..bcc14fefccd8 100644 --- a/assert/array_includes.ts +++ b/assert/array_includes.ts @@ -27,7 +27,6 @@ export type ArrayLikeArg = ArrayLike & object; * @param expected The array-like object to check for. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertArrayIncludes( actual: ArrayLikeArg, expected: ArrayLikeArg, diff --git a/assert/equals.ts b/assert/equals.ts index b34e218916fd..f0e355590a5b 100644 --- a/assert/equals.ts +++ b/assert/equals.ts @@ -41,7 +41,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertEquals( actual: T, expected: T, diff --git a/assert/greater.ts b/assert/greater.ts index fb5f76816e75..d3d8aa73463c 100644 --- a/assert/greater.ts +++ b/assert/greater.ts @@ -21,7 +21,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertGreater(actual: T, expected: T, msg?: string) { if (actual > expected) return; diff --git a/assert/greater_or_equal.ts b/assert/greater_or_equal.ts index 1fd891bd89bf..dbd8642045b4 100644 --- a/assert/greater_or_equal.ts +++ b/assert/greater_or_equal.ts @@ -21,7 +21,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertGreaterOrEqual( actual: T, expected: T, diff --git a/assert/instance_of.ts b/assert/instance_of.ts index a208b3986055..5856df063200 100644 --- a/assert/instance_of.ts +++ b/assert/instance_of.ts @@ -25,7 +25,6 @@ export type GetConstructorType = InstanceType; * @param expectedType The expected class constructor. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertInstanceOf< // deno-lint-ignore no-explicit-any T extends abstract new (...args: any[]) => any, diff --git a/assert/is_error.ts b/assert/is_error.ts index 69543ec8902e..22dab3f30904 100644 --- a/assert/is_error.ts +++ b/assert/is_error.ts @@ -26,7 +26,6 @@ import { stripAnsiCode } from "@std/internal/styles"; * @param msgMatches The optional string or RegExp to assert in the error message. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertIsError( error: unknown, // deno-lint-ignore no-explicit-any diff --git a/assert/less.ts b/assert/less.ts index cc47f332b4a3..4436bd2df1e1 100644 --- a/assert/less.ts +++ b/assert/less.ts @@ -20,7 +20,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertLess(actual: T, expected: T, msg?: string) { if (actual < expected) return; diff --git a/assert/less_or_equal.ts b/assert/less_or_equal.ts index bcdd369dcb67..6569eb62c34e 100644 --- a/assert/less_or_equal.ts +++ b/assert/less_or_equal.ts @@ -21,7 +21,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertLessOrEqual( actual: T, expected: T, diff --git a/assert/match.ts b/assert/match.ts index ee41ea2edd23..8c49ffa7dc54 100644 --- a/assert/match.ts +++ b/assert/match.ts @@ -18,7 +18,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected pattern to match. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertMatch( actual: string, expected: RegExp, diff --git a/assert/not_equals.ts b/assert/not_equals.ts index 009605b0079c..70bdab6033a4 100644 --- a/assert/not_equals.ts +++ b/assert/not_equals.ts @@ -24,7 +24,6 @@ import { format } from "@std/internal/format"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotEquals(actual: T, expected: T, msg?: string) { if (!equal(actual, expected)) { return; diff --git a/assert/not_instance_of.ts b/assert/not_instance_of.ts index ab46daef2d54..01bfdde07d49 100644 --- a/assert/not_instance_of.ts +++ b/assert/not_instance_of.ts @@ -20,7 +20,6 @@ import { assertFalse } from "./false.ts"; * @param unexpectedType The class constructor to check against. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotInstanceOf( actual: A, // deno-lint-ignore no-explicit-any diff --git a/assert/not_match.ts b/assert/not_match.ts index 8086ab25eb43..533ed170b735 100644 --- a/assert/not_match.ts +++ b/assert/not_match.ts @@ -18,7 +18,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to not match. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotMatch( actual: string, expected: RegExp, diff --git a/assert/not_strict_equals.ts b/assert/not_strict_equals.ts index a670cc2a4131..2c62099c59d9 100644 --- a/assert/not_strict_equals.ts +++ b/assert/not_strict_equals.ts @@ -24,7 +24,6 @@ import { format } from "@std/internal/format"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertNotStrictEquals( actual: T, expected: T, diff --git a/assert/object_match.ts b/assert/object_match.ts index ad1ad608f6dc..741dc17081b5 100644 --- a/assert/object_match.ts +++ b/assert/object_match.ts @@ -29,7 +29,6 @@ import { assertEquals } from "./equals.ts"; * @param expected The expected value to match. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertObjectMatch( // deno-lint-ignore no-explicit-any actual: Record, diff --git a/assert/rejects.ts b/assert/rejects.ts index 07334f92353c..b61aa317d762 100644 --- a/assert/rejects.ts +++ b/assert/rejects.ts @@ -53,7 +53,6 @@ export function assertRejects( msgIncludes?: string, msg?: string, ): Promise; -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertRejects( fn: () => PromiseLike, errorClassOrMsg?: diff --git a/assert/strict_equals.ts b/assert/strict_equals.ts index 4459139b9c7a..197a5c708d88 100644 --- a/assert/strict_equals.ts +++ b/assert/strict_equals.ts @@ -29,7 +29,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected value to compare. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertStrictEquals( actual: unknown, expected: T, diff --git a/assert/string_includes.ts b/assert/string_includes.ts index 7c9b511438e7..9791d460b7c8 100644 --- a/assert/string_includes.ts +++ b/assert/string_includes.ts @@ -18,7 +18,6 @@ import { AssertionError } from "./assertion_error.ts"; * @param expected The expected string to check for inclusion. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertStringIncludes( actual: string, expected: string, diff --git a/assert/throws.ts b/assert/throws.ts index 3afeb4d59b3c..392ff912c49f 100644 --- a/assert/throws.ts +++ b/assert/throws.ts @@ -56,7 +56,6 @@ export function assertThrows( msgIncludes?: string, msg?: string, ): E; -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertThrows( fn: () => unknown, errorClassOrMsg?: diff --git a/async/_util.ts b/async/_util.ts index 80c19bf4bddf..f1a461633800 100644 --- a/async/_util.ts +++ b/async/_util.ts @@ -1,7 +1,6 @@ // Copyright 2018-2025 the Deno authors. MIT license. // This module is browser compatible. -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function exponentialBackoffWithJitter( cap: number, base: number, diff --git a/cbor/_common_encode.ts b/cbor/_common_encode.ts index a6467a807e24..f05c04ef4138 100644 --- a/cbor/_common_encode.ts +++ b/cbor/_common_encode.ts @@ -60,7 +60,6 @@ export function calcEncodingSize(x: CborType): number { return size + calcHeaderSize(pairs); } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( input: CborType, output: Uint8Array, diff --git a/csv/_io.ts b/csv/_io.ts index cb9a39ab7dcd..dd164927ec86 100644 --- a/csv/_io.ts +++ b/csv/_io.ts @@ -56,7 +56,6 @@ export interface LineReader { isEOF(): boolean; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function parseRecord( fullLine: string, reader: LineReader, @@ -202,7 +201,6 @@ export async function parseRecord( return result; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createBareQuoteErrorMessage( zeroBasedRecordStartLine: number, zeroBasedLine: number, @@ -214,7 +212,6 @@ export function createBareQuoteErrorMessage( zeroBasedColumn + 1 }: bare " in non-quoted-field`; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createQuoteErrorMessage( zeroBasedRecordStartLine: number, zeroBasedLine: number, @@ -227,7 +224,6 @@ export function createQuoteErrorMessage( }: extraneous or missing " in quoted-field`; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function convertRowToObject( row: readonly string[], headers: readonly string[], diff --git a/encoding/_common16.ts b/encoding/_common16.ts index b6b038481600..bfb91fffd177 100644 --- a/encoding/_common16.ts +++ b/encoding/_common16.ts @@ -29,7 +29,6 @@ export function calcSizeHex(originalSize: number): number { return originalSize * 2; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( buffer: Uint8Array_, i: number, @@ -44,7 +43,6 @@ export function encode( return o; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function decode( buffer: Uint8Array_, i: number, diff --git a/encoding/_common32.ts b/encoding/_common32.ts index 96a4d176712c..a8bbdb054300 100644 --- a/encoding/_common32.ts +++ b/encoding/_common32.ts @@ -53,7 +53,6 @@ export function calcSizeBase32(rawSize: number): number { return ((rawSize + 4) / 5 | 0) * 8; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( buffer: Uint8Array_, i: number, @@ -129,7 +128,6 @@ export function encode( return o; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function decode( buffer: Uint8Array_, i: number, diff --git a/encoding/_common64.ts b/encoding/_common64.ts index 62d869d6ecef..e0a13c3b7bf2 100644 --- a/encoding/_common64.ts +++ b/encoding/_common64.ts @@ -51,7 +51,6 @@ export function calcSizeBase64(originalSize: number): number { return ((originalSize + 2) / 3 | 0) * 4; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function encode( buffer: Uint8Array_, i: number, @@ -88,7 +87,6 @@ export function encode( return o; } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function decode( buffer: Uint8Array_, i: number, diff --git a/expect/_assert_is_error.ts b/expect/_assert_is_error.ts index 4f73fd69cee7..f3abdce84eaf 100644 --- a/expect/_assert_is_error.ts +++ b/expect/_assert_is_error.ts @@ -15,7 +15,6 @@ import { stripAnsiCode } from "@std/internal/styles"; * @param msgMatches The optional string or RegExp to assert in the error message. * @param msg The optional message to display if the assertion fails. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertIsError( error: unknown, // deno-lint-ignore no-explicit-any diff --git a/expect/_matchers.ts b/expect/_matchers.ts index a30d25379b79..b03da0d2f29e 100644 --- a/expect/_matchers.ts +++ b/expect/_matchers.ts @@ -75,7 +75,6 @@ export function toStrictEqual( } } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toBeCloseTo( context: MatcherContext, expected: number, @@ -375,7 +374,6 @@ export function toHaveLength( } } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toHaveProperty( context: MatcherContext, propName: string | string[], @@ -743,7 +741,6 @@ export function toHaveBeenLastCalledWith( } } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toHaveBeenNthCalledWith( context: MatcherContext, nth: number, @@ -927,7 +924,6 @@ export function toHaveLastReturnedWith( } } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function toHaveNthReturnedWith( context: MatcherContext, nth: number, diff --git a/expect/_utils.ts b/expect/_utils.ts index b73b407f5706..bdc5974d7ada 100644 --- a/expect/_utils.ts +++ b/expect/_utils.ts @@ -85,7 +85,6 @@ function entries(obj: any) { } // Ported from https://github.com/jestjs/jest/blob/442c7f692e3a92f14a2fb56c1737b26fc663a0ef/packages/expect-utils/src/utils.ts#L173 -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function iterableEquality( // deno-lint-ignore no-explicit-any a: any, @@ -236,7 +235,6 @@ export function iterableEquality( } // Ported from https://github.com/jestjs/jest/blob/442c7f692e3a92f14a2fb56c1737b26fc663a0ef/packages/expect-utils/src/utils.ts#L341 -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function subsetEquality( object: unknown, subset: unknown, diff --git a/fs/_is_subdir.ts b/fs/_is_subdir.ts index 1bf7be9685d7..4fb1cd74f7fa 100644 --- a/fs/_is_subdir.ts +++ b/fs/_is_subdir.ts @@ -15,7 +15,6 @@ import { toPathString } from "./_to_path_string.ts"; * * @returns `true` if `src` is a sub-directory of `dest`, `false` otherwise. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function isSubdir( src: string | URL, dest: string | URL, diff --git a/json/_test_utils.ts b/json/_test_utils.ts index a17d4050b839..9f10fa4c8d77 100644 --- a/json/_test_utils.ts +++ b/json/_test_utils.ts @@ -3,7 +3,6 @@ import { assertEquals, assertRejects } from "@std/assert"; import type { ConcatenatedJsonParseStream } from "./concatenated_json_parse_stream.ts"; import type { JsonParseStream } from "./parse_stream.ts"; -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertValidParse( transform: typeof ConcatenatedJsonParseStream | typeof JsonParseStream, chunks: string[], @@ -15,7 +14,6 @@ export async function assertValidParse( assertEquals(res, expect); } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertInvalidParse( transform: typeof ConcatenatedJsonParseStream | typeof JsonParseStream, chunks: string[], diff --git a/path/_common/basename.ts b/path/_common/basename.ts index 9604fa77d891..dec849d53497 100644 --- a/path/_common/basename.ts +++ b/path/_common/basename.ts @@ -19,7 +19,6 @@ export function stripSuffix(name: string, suffix: string): string { return name.slice(0, -suffix.length); } -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function lastPathSegment( path: string, isSep: (char: number) => boolean, diff --git a/path/_common/normalize_string.ts b/path/_common/normalize_string.ts index 50903ef3d98c..dbcf59029bc3 100644 --- a/path/_common/normalize_string.ts +++ b/path/_common/normalize_string.ts @@ -6,7 +6,6 @@ import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./constants.ts"; // Resolves . and .. elements in a path with directory names -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function normalizeString( path: string, allowAboveRoot: boolean, diff --git a/streams/_test_utils.ts b/streams/_test_utils.ts index 35ae184b95d9..63e57859190d 100644 --- a/streams/_test_utils.ts +++ b/streams/_test_utils.ts @@ -8,7 +8,6 @@ import { assert, assertEquals } from "@std/assert"; * @param inputs Source input data * @param outputs Expected output data */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function testTransformStream( transform: TransformStream, inputs: Iterable | AsyncIterable, From 1ad5872539adb0b2c0ab6a956e508fe499b5f284 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 12 May 2025 16:11:06 +0900 Subject: [PATCH 08/12] fix test case --- _tools/lint_plugin.ts | 5 +++-- _tools/lint_plugin_test.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 3eeac8b01db5..07c86d8a004c 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -8,6 +8,7 @@ import { toCamelCase, toPascalCase } from "@std/text"; import { toFileUrl } from "@std/path/to-file-url"; +import { resolve } from "@std/path/resolve"; const PASCAL_CASE_REGEXP = /^_?(?:[A-Z][a-z0-9]*)*_?$/; const UPPER_CASE_ONLY = /^_?[A-Z]{2,}$/; @@ -314,7 +315,7 @@ export default { // https://docs.deno.com/runtime/contributing/style_guide/#exported-functions%3A-max-2-args%2C-put-the-rest-into-an-options-object "exported-function-args-maximum": { create(context) { - const url = toFileUrl(context.filename); + const url = toFileUrl(resolve(context.filename)); if (url.href.includes("/assert/")) { // assert module generally don't follow this rule return {}; @@ -343,7 +344,7 @@ export default { return context.report({ node: id ?? declaration, message: - "Third argument of export function is not an options object.", + "Third argument of export function is not an options object or function.", hint: "Export functions can have 0-2 required arguments, plus (if necessary) an options object (so max 3 total).", }); diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 029de106c89c..4d13fa55473c 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -11,7 +11,7 @@ function assertLintPluginDiagnostics( ) { const actualDiagnostics = Deno.lint.runPlugin( lintPlugin, - "main.ts", // Dummy filename, file doesn't need to exist. + "/main.ts", // Dummy filename, file doesn't need to exist. source, ); assertEquals(actualDiagnostics, expectedDiagnostics); @@ -353,7 +353,8 @@ export function foo(bar: unknown, baz: unknown, bat: unknown, options: Record Date: Mon, 12 May 2025 16:27:20 +0900 Subject: [PATCH 09/12] reduce false positves --- _tools/lint_plugin.ts | 22 ++++++++++++++-------- _tools/lint_plugin_test.ts | 2 +- async/pool.ts | 1 - bytes/copy.ts | 1 - bytes/includes_needle.ts | 1 - bytes/index_of_needle.ts | 1 - bytes/last_index_of_needle.ts | 1 - internal/diff.ts | 2 -- testing/mock.ts | 1 - 9 files changed, 15 insertions(+), 17 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 07c86d8a004c..3f4750d5106b 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -316,14 +316,16 @@ export default { "exported-function-args-maximum": { create(context) { const url = toFileUrl(resolve(context.filename)); - if (url.href.includes("/assert/")) { - // assert module generally don't follow this rule - return {}; - } - if (url.href.includes("/_")) { - // exports from private utils don't need to follow this rule - return {}; - } + + // assert module generally don't follow this rule + if (url.href.includes("/assert/")) return {}; + // exports from private utils don't need to follow this rule + if (url.href.includes("/_")) return {}; + // internal exports don't need to follow this rule + if (url.href.includes("/internal/")) return {}; + // bytes API generally don't follow this rule + if (url.href.includes("/bytes/")) return {}; + return { ExportNamedDeclaration(node) { if (node.declaration?.type !== "FunctionDeclaration") return; @@ -335,6 +337,10 @@ export default { switch (param.type) { case "Identifier": if (param.name === "options") return; + if ( + param.typeAnnotation?.typeAnnotation?.type === + "TSFunctionType" + ) return; break; case "AssignmentPattern": { if (param.right.type === "ObjectExpression") return; diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 4d13fa55473c..942d431950bb 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -11,7 +11,7 @@ function assertLintPluginDiagnostics( ) { const actualDiagnostics = Deno.lint.runPlugin( lintPlugin, - "/main.ts", // Dummy filename, file doesn't need to exist. + "main.ts", // Dummy filename, file doesn't need to exist. source, ); assertEquals(actualDiagnostics, expectedDiagnostics); diff --git a/async/pool.ts b/async/pool.ts index 25f092ee3e1e..d8a9f853b29a 100644 --- a/async/pool.ts +++ b/async/pool.ts @@ -36,7 +36,6 @@ const ERROR_WHILE_MAPPING_MESSAGE = * @param iteratorFn The function to call for every item of the array. * @returns The async iterator with the transformed values. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function pooledMap( poolLimit: number, array: Iterable | AsyncIterable, diff --git a/bytes/copy.ts b/bytes/copy.ts index df7596d44f51..1d85b762e711 100644 --- a/bytes/copy.ts +++ b/bytes/copy.ts @@ -40,7 +40,6 @@ * Defining an offset will start copying at the specified index in the * destination array. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function copy(src: Uint8Array, dst: Uint8Array, offset = 0): number { offset = Math.max(0, Math.min(offset, dst.byteLength)); const dstBytesAvailable = dst.byteLength - offset; diff --git a/bytes/includes_needle.ts b/bytes/includes_needle.ts index 67b321f59da2..90ecb5aaf4fb 100644 --- a/bytes/includes_needle.ts +++ b/bytes/includes_needle.ts @@ -39,7 +39,6 @@ import { indexOfNeedle } from "./index_of_needle.ts"; * ``` * The search will start at the specified index in the source array. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function includesNeedle( source: Uint8Array, needle: Uint8Array, diff --git a/bytes/index_of_needle.ts b/bytes/index_of_needle.ts index b89c1766d31e..988965f9c39f 100644 --- a/bytes/index_of_needle.ts +++ b/bytes/index_of_needle.ts @@ -44,7 +44,6 @@ * Defining a start index will begin the search at the specified index in the * source array. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function indexOfNeedle( source: Uint8Array, needle: Uint8Array, diff --git a/bytes/last_index_of_needle.ts b/bytes/last_index_of_needle.ts index 0f85133b3c61..1b70c172d3ca 100644 --- a/bytes/last_index_of_needle.ts +++ b/bytes/last_index_of_needle.ts @@ -41,7 +41,6 @@ * Defining a start index will begin the search at the specified index in the * source array. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function lastIndexOfNeedle( source: Uint8Array, needle: Uint8Array, diff --git a/internal/diff.ts b/internal/diff.ts index f77e74ceee46..e6c530550b0f 100644 --- a/internal/diff.ts +++ b/internal/diff.ts @@ -108,7 +108,6 @@ export function assertFp(value: unknown): asserts value is FarthestPoint { * ); * ``` */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function backTrace( A: T[], B: T[], @@ -185,7 +184,6 @@ export function backTrace( * ); * ``` */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function createFp( k: number, M: number, diff --git a/testing/mock.ts b/testing/mock.ts index 1e87a501ed7a..4e66f0db642d 100644 --- a/testing/mock.ts +++ b/testing/mock.ts @@ -1052,7 +1052,6 @@ export function stub< ...args: GetParametersFromProp ) => GetReturnFromProp, ): Stub, GetReturnFromProp>; -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function stub< Self, Args extends unknown[], From 804b18fbbe8299b7b6685e25947904a7afce41c7 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 12 May 2025 16:30:58 +0900 Subject: [PATCH 10/12] reduce false positives --- _tools/lint_plugin.ts | 5 ++++- testing/mock.ts | 4 ---- testing/snapshot.ts | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 3f4750d5106b..51305843898c 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -317,8 +317,11 @@ export default { create(context) { const url = toFileUrl(resolve(context.filename)); - // assert module generally don't follow this rule + // assertions and testing utils generally don't follow this rule if (url.href.includes("/assert/")) return {}; + if (url.href.includes("/testing/mock.ts")) return {}; + if (url.href.includes("/testing/snapshot.ts")) return {}; + // exports from private utils don't need to follow this rule if (url.href.includes("/_")) return {}; // internal exports don't need to follow this rule diff --git a/testing/mock.ts b/testing/mock.ts index 4e66f0db642d..049c2c16bb68 100644 --- a/testing/mock.ts +++ b/testing/mock.ts @@ -1256,7 +1256,6 @@ function getSpyCall< * @param callIndex The index of the call to check * @param expected The expected spy call. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertSpyCall< Self, Args extends unknown[], @@ -1356,7 +1355,6 @@ export function assertSpyCall< * @param callIndex The index of the call to check * @param expected The expected spy call. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertSpyCallAsync< Self, Args extends unknown[], @@ -1458,7 +1456,6 @@ export async function assertSpyCallAsync< * @param expected The expected argument. * @returns The actual argument. */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertSpyCallArg< Self, Args extends unknown[], @@ -1593,7 +1590,6 @@ export function assertSpyCallArgs< argsEnd: number, expected: ExpectedArgs, ): ExpectedArgs; -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function assertSpyCallArgs< ExpectedArgs extends unknown[], Args extends unknown[], diff --git a/testing/snapshot.ts b/testing/snapshot.ts index c45142806e4b..c70f97909523 100644 --- a/testing/snapshot.ts +++ b/testing/snapshot.ts @@ -572,7 +572,6 @@ export async function assertSnapshot( actual: T, message?: string, ): Promise; -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export async function assertSnapshot( context: Deno.TestContext, actual: unknown, From 664cafe81020871a5373c6282bf8cd6873059c5f Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 12 May 2025 16:37:30 +0900 Subject: [PATCH 11/12] reduce false positives --- _tools/lint_plugin.ts | 8 ++++++++ http/cookie.ts | 1 - testing/unstable_stub.ts | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 51305843898c..01b5ac316b29 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -320,6 +320,7 @@ export default { // assertions and testing utils generally don't follow this rule if (url.href.includes("/assert/")) return {}; if (url.href.includes("/testing/mock.ts")) return {}; + if (url.href.includes("/testing/unstable_stub.ts")) return {}; if (url.href.includes("/testing/snapshot.ts")) return {}; // exports from private utils don't need to follow this rule @@ -340,16 +341,23 @@ export default { switch (param.type) { case "Identifier": if (param.name === "options") return; + // Function as 3rd argument is valid (e.g. pooledMap) if ( param.typeAnnotation?.typeAnnotation?.type === "TSFunctionType" ) return; + // attributes: Pick as 3rd argument is valid + if ( + param.typeAnnotation?.typeAnnotation?.typeName?.name === + "Pick" + ) return; break; case "AssignmentPattern": { if (param.right.type === "ObjectExpression") return; break; } } + return context.report({ node: id ?? declaration, message: diff --git a/http/cookie.ts b/http/cookie.ts index f5cd602dc99c..93b0bdc4b17e 100644 --- a/http/cookie.ts +++ b/http/cookie.ts @@ -324,7 +324,6 @@ export function setCookie(headers: Headers, cookie: Cookie) { * @param name Name of cookie * @param attributes Additional cookie attributes */ -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function deleteCookie( headers: Headers, name: string, diff --git a/testing/unstable_stub.ts b/testing/unstable_stub.ts index 2080dfb801e4..93800f805e7a 100644 --- a/testing/unstable_stub.ts +++ b/testing/unstable_stub.ts @@ -149,7 +149,6 @@ export function stub( GetReturnFromProp >; }; -// deno-lint-ignore deno-style-guide/exported-function-args-maximum export function stub( self: Self, property: keyof Self, From d5d1510116a195c670d4bbc0e4427a97c14dbc6c Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 12 May 2025 16:46:07 +0900 Subject: [PATCH 12/12] add test cases --- _tools/lint_plugin_test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 942d431950bb..2d98cd797963 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -334,6 +334,12 @@ export function foo(bar: unknown) { export function foo(bar: unknown, baz: unknown) { } export function foo(bar: unknown, baz: unknown, options: Record) { +} +// function as last argument is allowed +export function foo(bar: unknown, baz: unknown, bat: () => unknown) { +} +// Pick is usually an object +export function foo(bar: unknown, baz: unknown, bat: Pick) { } `, [],