From e549dd7f211417cd3fd83a5bdbc7b611089ec733 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Tue, 8 Apr 2025 22:59:58 +1000 Subject: [PATCH 1/8] chore: add `no-top-level-arrow-syntax` to Deno Style Guide linter plugin --- _tools/lint_plugin.ts | 25 +++++++++++++++++++++++++ _tools/lint_plugin_test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index c34b2a275888..7e06bf0a3c09 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -38,5 +38,30 @@ export default { }; }, }, + // https://docs.deno.com/runtime/contributing/style_guide/#top-level-functions-should-not-use-arrow-syntax + "no-top-level-arrow-syntax": { + create(context) { + return { + // TODO(iuioiua): Use `VariableDeclaration` once https://github.com/denoland/deno/issues/28799 is fixed + Program(node) { + for (const child of node.body) { + if ( + child.declaration.kind !== "const" && + !child.declaration.declarations?.some((d) => + d.init?.type === "ArrowFunctionExpression" + ) + ) continue; + context.report({ + node: child, + range: child.range, + message: "Top-level functions should not use arrow syntax", + hint: + "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", + }); + } + }, + }; + }, + }, }, } satisfies Deno.lint.Plugin; diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 9915a65bb186..5cad1929f40f 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -55,3 +55,34 @@ class MyClass { }], ); }); + +Deno.test("deno-style-guide/no-top-level-arrow-syntax", { + ignore: !Deno.version.deno.startsWith("2"), +}, () => { + // Bad + assertLintPluginDiagnostics( + ` +export const foo = (): string => { + return "bar"; +}; +`, + [{ + id: "deno-style-guide/no-top-level-arrow-syntax", + range: [1, 54], + fix: [], + message: "Top-level functions should not use arrow syntax", + hint: + "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", + }], + ); + + // Good + assertLintPluginDiagnostics( + ` +export function foo(): string { + return "bar"; +} +`, + [], + ); +}); From c80d616419e77e6e4205233c5200861d5071da3a Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 9 Apr 2025 08:09:34 +1000 Subject: [PATCH 2/8] update --- _tools/lint_plugin.ts | 30 +++++++++++++----------------- _tools/lint_plugin_test.ts | 3 ++- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 7e06bf0a3c09..002ac0b04e53 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -42,23 +42,19 @@ export default { "no-top-level-arrow-syntax": { create(context) { return { - // TODO(iuioiua): Use `VariableDeclaration` once https://github.com/denoland/deno/issues/28799 is fixed - Program(node) { - for (const child of node.body) { - if ( - child.declaration.kind !== "const" && - !child.declaration.declarations?.some((d) => - d.init?.type === "ArrowFunctionExpression" - ) - ) continue; - context.report({ - node: child, - range: child.range, - message: "Top-level functions should not use arrow syntax", - hint: - "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", - }); - } + // TODO(iuioiua): Should work once https://github.com/denoland/deno/issues/28799 is fixed + ArrowFunctionExpression(node) { + if ( + node.parent.type !== "VariableDeclarator" && + node.parent.parent.type !== "Program" + ) return; + context.report({ + node, + range: node.range, + message: "Top-level functions should not use arrow syntax", + hint: + "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", + }); }, }; }, diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 5cad1929f40f..b6b5a7f4efc8 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -68,7 +68,8 @@ export const foo = (): string => { `, [{ id: "deno-style-guide/no-top-level-arrow-syntax", - range: [1, 54], + // TODO(iuioiua): Should this not start from `const`? + range: [20, 53], fix: [], message: "Top-level functions should not use arrow syntax", hint: From 1bee34720f64d4a61d7a8a9fe7893616bb5c2ef7 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 10 Apr 2025 18:05:43 +1000 Subject: [PATCH 3/8] work --- _tools/lint_plugin_test.ts | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index b6b5a7f4efc8..234c4ec41ded 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -61,29 +61,28 @@ Deno.test("deno-style-guide/no-top-level-arrow-syntax", { }, () => { // Bad assertLintPluginDiagnostics( - ` -export const foo = (): string => { - return "bar"; -}; -`, - [{ - id: "deno-style-guide/no-top-level-arrow-syntax", - // TODO(iuioiua): Should this not start from `const`? - range: [20, 53], - fix: [], - message: "Top-level functions should not use arrow syntax", - hint: - "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", - }], + 'const foo = () => "bar";', + [ + { + id: "deno-style-guide/no-top-level-arrow-syntax", + // TODO(iuioiua): Should this not start from `const`? + range: [12, 23], + fix: [], + message: "Top-level functions should not use arrow syntax", + hint: + "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", + }, + ], ); // Good assertLintPluginDiagnostics( ` -export function foo(): string { +function foo() { + const bar = () => "baz"; + return "bar"; -} -`, +}`, [], ); }); From 0dcb951ef889638c2c74b85f4ef28ad0dc6a9d86 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 10 Apr 2025 21:52:21 +1000 Subject: [PATCH 4/8] work --- _tools/lint_plugin.ts | 24 +++++++++++++----------- _tools/lint_plugin_test.ts | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index 002ac0b04e53..e2f1cb4b2566 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -42,19 +42,21 @@ export default { "no-top-level-arrow-syntax": { create(context) { return { - // TODO(iuioiua): Should work once https://github.com/denoland/deno/issues/28799 is fixed ArrowFunctionExpression(node) { if ( - node.parent.type !== "VariableDeclarator" && - node.parent.parent.type !== "Program" - ) return; - context.report({ - node, - range: node.range, - message: "Top-level functions should not use arrow syntax", - hint: - "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", - }); + node.parent.type === "VariableDeclarator" && + node.parent.parent.type === "VariableDeclaration" && + (node.parent.parent.parent.type === "Program" || + node.parent.parent.parent.type === "ExportNamedDeclaration") + ) { + context.report({ + node, + range: node.range, + message: "Top-level functions should not use arrow syntax", + hint: + "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", + }); + } }, }; }, diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 234c4ec41ded..0e1aa1e7a590 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -61,12 +61,22 @@ Deno.test("deno-style-guide/no-top-level-arrow-syntax", { }, () => { // Bad assertLintPluginDiagnostics( - 'const foo = () => "bar";', + ` +const foo = () => "bar"; +export const bar = () => "foo"; + `, [ { id: "deno-style-guide/no-top-level-arrow-syntax", - // TODO(iuioiua): Should this not start from `const`? - range: [12, 23], + range: [13, 24], + fix: [], + message: "Top-level functions should not use arrow syntax", + hint: + "Use function declaration instead of arrow function. E.g. Use `function foo() {}` instead of `const foo = () => {}`.", + }, + { + id: "deno-style-guide/no-top-level-arrow-syntax", + range: [45, 56], fix: [], message: "Top-level functions should not use arrow syntax", hint: From ecba34f6f580c91bb93e66ea6b15e797e15f5fd6 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 10 Apr 2025 21:54:40 +1000 Subject: [PATCH 5/8] fix --- _tools/lint_plugin.ts | 245 +++++++++++++++++++++--------------------- 1 file changed, 124 insertions(+), 121 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index a4f8d4b9eeca..dbdee5ba41d1 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -76,133 +76,136 @@ export default { }); } }, - // https://docs.deno.com/runtime/contributing/style_guide/#naming-convention/ - "naming-convention": { - create(context) { - return { - TSTypeAliasDeclaration(node) { - const name = node.id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: node.id, - message: `Type name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(node.id, toPascalCase(name)); + // https://docs.deno.com/runtime/contributing/style_guide/#naming-convention/ + "naming-convention": { + create(context) { + return { + TSTypeAliasDeclaration(node) { + const name = node.id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: node.id, + message: `Type name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(node.id, toPascalCase(name)); + }, + }); + } }, - }); - } - }, - TSInterfaceDeclaration(node) { - const name = node.id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: node.id, - message: `Interface name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(node.id, toPascalCase(name)); + TSInterfaceDeclaration(node) { + const name = node.id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: node.id, + message: `Interface name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(node.id, toPascalCase(name)); + }, + }); + } }, - }); - } - }, - TSEnumDeclaration(node) { - const name = node.id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: node.id, - message: `Enum name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(node.id, toPascalCase(name)); + TSEnumDeclaration(node) { + const name = node.id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: node.id, + message: `Enum name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(node.id, toPascalCase(name)); + }, + }); + } }, - }); - } - }, - FunctionDeclaration(node) { - const id = node.id; - if (!id) return; - const name = id.name; - if (!name) return; - if (!isCamelCase(name)) { - context.report({ - node: id, - message: `Function name '${name}' is not camelCase.`, - fix(fixer) { - return fixer.replaceText(id, toCamelCase(name)); + FunctionDeclaration(node) { + const id = node.id; + if (!id) return; + const name = id.name; + if (!name) return; + if (!isCamelCase(name)) { + context.report({ + node: id, + message: `Function name '${name}' is not camelCase.`, + fix(fixer) { + return fixer.replaceText(id, toCamelCase(name)); + }, + }); + } }, - }); - } - }, - ClassDeclaration(node) { - const id = node.id; - if (!id) return; - const name = id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: id, - message: `Class name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(id, toPascalCase(name)); + ClassDeclaration(node) { + const id = node.id; + if (!id) return; + const name = id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: id, + message: `Class name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(id, toPascalCase(name)); + }, + }); + } }, - }); - } - }, - MethodDefinition(node) { - const key = node.key; - if (key.type !== "Identifier") return; - const name = key.name; - if (!name) return; - if (!isCamelCase(name)) { - context.report({ - node: key, - message: `Method name '${name}' is not camelCase.`, - fix(fixer) { - return fixer.replaceText(key, toCamelCase(name)); + MethodDefinition(node) { + const key = node.key; + if (key.type !== "Identifier") return; + const name = key.name; + if (!name) return; + if (!isCamelCase(name)) { + context.report({ + node: key, + message: `Method name '${name}' is not camelCase.`, + fix(fixer) { + return fixer.replaceText(key, toCamelCase(name)); + }, + }); + } }, - }); - } - }, - PropertyDefinition(node) { - const key = node.key; - switch (key.type) { - case "Identifier": - case "PrivateIdentifier": { - const name = key.name; - if (!name) return; - if (!isCamelCase(name)) { - context.report({ - node: key, - message: `Property name '${name}' is not camelCase.`, - fix(fixer) { - return fixer.replaceText(key, toCamelCase(name)); - }, - }); - } - break; - } - default: - break; - } - }, - VariableDeclaration(node) { - for (const declaration of node.declarations) { - const id = declaration.id; - if (id.type !== "Identifier") return; - const name = id.name; - if (!name) return; - if ( - !isConstantCase(name) && !isCamelCase(name) && - !isPascalCase(name) - ) { - context.report({ - node: id, - message: - `Variable name '${name}' is not camelCase, PascalCase, or CONSTANT_CASE.`, - }); - } - } + PropertyDefinition(node) { + const key = node.key; + switch (key.type) { + case "Identifier": + case "PrivateIdentifier": { + const name = key.name; + if (!name) return; + if (!isCamelCase(name)) { + context.report({ + node: key, + message: `Property name '${name}' is not camelCase.`, + fix(fixer) { + return fixer.replaceText(key, toCamelCase(name)); + }, + }); + } + break; + } + default: + break; + } + }, + VariableDeclaration(node) { + for (const declaration of node.declarations) { + const id = declaration.id; + if (id.type !== "Identifier") return; + const name = id.name; + if (!name) return; + if ( + !isConstantCase(name) && !isCamelCase(name) && + !isPascalCase(name) + ) { + context.report({ + node: id, + message: + `Variable name '${name}' is not camelCase, PascalCase, or CONSTANT_CASE.`, + }); + } + } + }, + }; + }, }, }; }, From f712c02bc460e8eb18c14357f34d30b8dcc0ba50 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 10 Apr 2025 22:06:15 +1000 Subject: [PATCH 6/8] work --- _tools/lint_plugin.ts | 249 +++++++++++++++++----------------- _tools/lint_plugin_test.ts | 1 + assert/equals_test.ts | 34 +++-- expect/_assert_equals_test.ts | 34 +++-- expect/_extend_test.ts | 4 +- expect/_to_equal_test.ts | 34 +++-- fs/_map_error.ts | 14 +- ini/stringify.ts | 4 +- log/base_handler.ts | 6 +- log/formatters_test.ts | 5 +- 10 files changed, 202 insertions(+), 183 deletions(-) diff --git a/_tools/lint_plugin.ts b/_tools/lint_plugin.ts index dbdee5ba41d1..8c9a9877fb8b 100644 --- a/_tools/lint_plugin.ts +++ b/_tools/lint_plugin.ts @@ -67,6 +67,7 @@ export default { (node.parent.parent.parent.type === "Program" || node.parent.parent.parent.type === "ExportNamedDeclaration") ) { + // TODO(iuioiua): add fix context.report({ node, range: node.range, @@ -76,136 +77,136 @@ export default { }); } }, - // https://docs.deno.com/runtime/contributing/style_guide/#naming-convention/ - "naming-convention": { - create(context) { - return { - TSTypeAliasDeclaration(node) { - const name = node.id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: node.id, - message: `Type name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(node.id, toPascalCase(name)); - }, - }); - } - }, - TSInterfaceDeclaration(node) { - const name = node.id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: node.id, - message: `Interface name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(node.id, toPascalCase(name)); - }, - }); - } - }, - TSEnumDeclaration(node) { - const name = node.id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: node.id, - message: `Enum name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(node.id, toPascalCase(name)); - }, - }); - } + }; + }, + }, + // https://docs.deno.com/runtime/contributing/style_guide/#naming-convention/ + "naming-convention": { + create(context) { + return { + TSTypeAliasDeclaration(node) { + const name = node.id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: node.id, + message: `Type name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(node.id, toPascalCase(name)); }, - FunctionDeclaration(node) { - const id = node.id; - if (!id) return; - const name = id.name; - if (!name) return; - if (!isCamelCase(name)) { - context.report({ - node: id, - message: `Function name '${name}' is not camelCase.`, - fix(fixer) { - return fixer.replaceText(id, toCamelCase(name)); - }, - }); - } + }); + } + }, + TSInterfaceDeclaration(node) { + const name = node.id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: node.id, + message: `Interface name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(node.id, toPascalCase(name)); }, - ClassDeclaration(node) { - const id = node.id; - if (!id) return; - const name = id.name; - if (!name) return; - if (!isPascalCase(name)) { - context.report({ - node: id, - message: `Class name '${name}' is not PascalCase.`, - fix(fixer) { - return fixer.replaceText(id, toPascalCase(name)); - }, - }); - } + }); + } + }, + TSEnumDeclaration(node) { + const name = node.id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: node.id, + message: `Enum name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(node.id, toPascalCase(name)); }, - MethodDefinition(node) { - const key = node.key; - if (key.type !== "Identifier") return; - const name = key.name; - if (!name) return; - if (!isCamelCase(name)) { - context.report({ - node: key, - message: `Method name '${name}' is not camelCase.`, - fix(fixer) { - return fixer.replaceText(key, toCamelCase(name)); - }, - }); - } + }); + } + }, + FunctionDeclaration(node) { + const id = node.id; + if (!id) return; + const name = id.name; + if (!name) return; + if (!isCamelCase(name)) { + context.report({ + node: id, + message: `Function name '${name}' is not camelCase.`, + fix(fixer) { + return fixer.replaceText(id, toCamelCase(name)); }, - PropertyDefinition(node) { - const key = node.key; - switch (key.type) { - case "Identifier": - case "PrivateIdentifier": { - const name = key.name; - if (!name) return; - if (!isCamelCase(name)) { - context.report({ - node: key, - message: `Property name '${name}' is not camelCase.`, - fix(fixer) { - return fixer.replaceText(key, toCamelCase(name)); - }, - }); - } - break; - } - default: - break; - } + }); + } + }, + ClassDeclaration(node) { + const id = node.id; + if (!id) return; + const name = id.name; + if (!name) return; + if (!isPascalCase(name)) { + context.report({ + node: id, + message: `Class name '${name}' is not PascalCase.`, + fix(fixer) { + return fixer.replaceText(id, toPascalCase(name)); }, - VariableDeclaration(node) { - for (const declaration of node.declarations) { - const id = declaration.id; - if (id.type !== "Identifier") return; - const name = id.name; - if (!name) return; - if ( - !isConstantCase(name) && !isCamelCase(name) && - !isPascalCase(name) - ) { - context.report({ - node: id, - message: - `Variable name '${name}' is not camelCase, PascalCase, or CONSTANT_CASE.`, - }); - } - } + }); + } + }, + MethodDefinition(node) { + const key = node.key; + if (key.type !== "Identifier") return; + const name = key.name; + if (!name) return; + if (!isCamelCase(name)) { + context.report({ + node: key, + message: `Method name '${name}' is not camelCase.`, + fix(fixer) { + return fixer.replaceText(key, toCamelCase(name)); }, - }; - }, + }); + } + }, + PropertyDefinition(node) { + const key = node.key; + switch (key.type) { + case "Identifier": + case "PrivateIdentifier": { + const name = key.name; + if (!name) return; + if (!isCamelCase(name)) { + context.report({ + node: key, + message: `Property name '${name}' is not camelCase.`, + fix(fixer) { + return fixer.replaceText(key, toCamelCase(name)); + }, + }); + } + break; + } + default: + break; + } + }, + VariableDeclaration(node) { + for (const declaration of node.declarations) { + const id = declaration.id; + if (id.type !== "Identifier") return; + const name = id.name; + if (!name) return; + if ( + !isConstantCase(name) && !isCamelCase(name) && + !isPascalCase(name) + ) { + context.report({ + node: id, + message: + `Variable name '${name}' is not camelCase, PascalCase, or CONSTANT_CASE.`, + }); + } + } }, }; }, diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 866c8a978c4c..692b7ebebda8 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -95,6 +95,7 @@ function foo() { }`, [], ); +}); Deno.test("deno-style-guide/naming-convention", { ignore: !Deno.version.deno.startsWith("2"), diff --git a/assert/equals_test.ts b/assert/equals_test.ts index db33a14091c4..2f9bd29b9908 100644 --- a/assert/equals_test.ts +++ b/assert/equals_test.ts @@ -9,22 +9,26 @@ import { yellow, } from "@std/internal/styles"; -const createHeader = (): string[] => [ - "", - "", - ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ - green( - bold("Expected"), - ) - }`, - "", - "", -]; +function createHeader(): string[] { + return [ + "", + "", + ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ + green( + bold("Expected"), + ) + }`, + "", + "", + ]; +} -const added: (s: string) => string = (s: string): string => - green(bold(stripAnsiCode(s))); -const removed: (s: string) => string = (s: string): string => - red(bold(stripAnsiCode(s))); +function added(s: string): string { + return green(bold(stripAnsiCode(s))); +} +function removed(s: string): string { + return red(bold(stripAnsiCode(s))); +} Deno.test({ name: "assertEquals() matches when values are equal", diff --git a/expect/_assert_equals_test.ts b/expect/_assert_equals_test.ts index dd6d57a6abd8..ef2a0df8618c 100644 --- a/expect/_assert_equals_test.ts +++ b/expect/_assert_equals_test.ts @@ -6,22 +6,26 @@ import { AssertionError, assertThrows } from "@std/assert"; import { bold, gray, green, red, stripAnsiCode, yellow } from "@std/fmt/colors"; import { assertEquals } from "./_assert_equals.ts"; -const createHeader = (): string[] => [ - "", - "", - ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ - green( - bold("Expected"), - ) - }`, - "", - "", -]; +function createHeader(): string[] { + return [ + "", + "", + ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ + green( + bold("Expected"), + ) + }`, + "", + "", + ]; +} -const added: (s: string) => string = (s: string): string => - green(bold(stripAnsiCode(s))); -const removed: (s: string) => string = (s: string): string => - red(bold(stripAnsiCode(s))); +function added(s: string): string { + return green(bold(stripAnsiCode(s))); +} +function removed(s: string): string { + return red(bold(stripAnsiCode(s))); +} Deno.test({ name: "assertEquals() matches when values are equal", diff --git a/expect/_extend_test.ts b/expect/_extend_test.ts index 964813afe379..98352b437fba 100644 --- a/expect/_extend_test.ts +++ b/expect/_extend_test.ts @@ -28,7 +28,7 @@ class Book { } } -const areAuthorsEqual: Tester = (a: unknown, b: unknown) => { +function areAuthorsEqual(a: unknown, b: unknown) { const isAAuthor = a instanceof Author; const isBAuthor = b instanceof Author; @@ -39,7 +39,7 @@ const areAuthorsEqual: Tester = (a: unknown, b: unknown) => { } else { return false; } -}; +} const areBooksEqual: Tester = function ( this: MatcherContext, diff --git a/expect/_to_equal_test.ts b/expect/_to_equal_test.ts index 6dfe51b9177d..2ada39047e34 100644 --- a/expect/_to_equal_test.ts +++ b/expect/_to_equal_test.ts @@ -4,22 +4,26 @@ import { bold, gray, green, red, stripAnsiCode, yellow } from "@std/fmt/colors"; import { AssertionError, assertThrows } from "@std/assert"; import { expect } from "./expect.ts"; -const createHeader = (): string[] => [ - "", - "", - ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ - green( - bold("Expected"), - ) - }`, - "", - "", -]; +function createHeader(): string[] { + return [ + "", + "", + ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ + green( + bold("Expected"), + ) + }`, + "", + "", + ]; +} -const added: (s: string) => string = (s: string): string => - green(bold(stripAnsiCode(s))); -const removed: (s: string) => string = (s: string): string => - red(bold(stripAnsiCode(s))); +function added(s: string): string { + return green(bold(stripAnsiCode(s))); +} +function removed(s: string): string { + return red(bold(stripAnsiCode(s))); +} Deno.test({ name: "expect().toEqual() matches when values are equal", diff --git a/fs/_map_error.ts b/fs/_map_error.ts index 99f84b895154..223f5a7ca0f9 100644 --- a/fs/_map_error.ts +++ b/fs/_map_error.ts @@ -6,10 +6,12 @@ type Class = new (...params: unknown[]) => T; type ClassOrT = T extends Class ? U : T; -const mapper = (Ctor: typeof errors[keyof typeof errors]) => (err: Error) => - Object.assign(new Ctor(err.message), { - stack: err.stack, - }) as unknown as ClassOrT; +function mapper(Ctor: typeof errors[keyof typeof errors]) { + return (err: Error) => + Object.assign(new Ctor(err.message), { + stack: err.stack, + }) as unknown as ClassOrT; +} const map: Record> = { EEXIST: mapper(errors.AlreadyExists), @@ -17,9 +19,9 @@ const map: Record> = { EBADF: mapper(errors.BadResource), }; -const isNodeErr = (e: unknown): e is Error & { code: string } => { +function isNodeErr(e: unknown): e is Error & { code: string } { return e instanceof Error && "code" in e; -}; +} export function mapError(e: E) { if (!isNodeErr(e)) return e; diff --git a/ini/stringify.ts b/ini/stringify.ts index 832509ba1c3c..a89cd938e317 100644 --- a/ini/stringify.ts +++ b/ini/stringify.ts @@ -36,11 +36,11 @@ function isPlainObject(object: unknown): object is object { return Object.prototype.toString.call(object) === "[object Object]"; } -const sort = ([_a, valA]: [string, unknown], [_b, valB]: [string, unknown]) => { +function sort([_a, valA]: [string, unknown], [_b, valB]: [string, unknown]) { if (isPlainObject(valA)) return 1; if (isPlainObject(valB)) return -1; return 0; -}; +} function defaultReplacer(_key: string, value: unknown, _section?: string) { return `${value}`; diff --git a/log/base_handler.ts b/log/base_handler.ts index 92ea897343d7..62f07ae80915 100644 --- a/log/base_handler.ts +++ b/log/base_handler.ts @@ -17,8 +17,10 @@ export type { LevelName, LogLevel, LogRecord }; * @returns A string representation of the log record. */ export type FormatterFunction = (logRecord: LogRecord) => string; -const DEFAULT_FORMATTER: FormatterFunction = ({ levelName, msg }) => - `${levelName} ${msg}`; +// deno-lint-ignore deno-style-guide/naming-convention +function DEFAULT_FORMATTER(logRecord: LogRecord): string { + return `${logRecord.levelName} ${logRecord.msg}`; +} /** Options for {@linkcode BaseHandler}. */ export interface BaseHandlerOptions { diff --git a/log/formatters_test.ts b/log/formatters_test.ts index 00e7f306ae84..bd1ee0ed9516 100644 --- a/log/formatters_test.ts +++ b/log/formatters_test.ts @@ -4,13 +4,14 @@ import { FakeTime } from "@std/testing/time"; import { jsonFormatter } from "./formatters.ts"; import { LogRecord } from "./logger.ts"; -const log = (msg: string, args: unknown[] = []) => - new LogRecord({ +function log(msg: string, args: unknown[] = []) { + return new LogRecord({ msg, args, level: 20, loggerName: "user-logger", }); +} Deno.test("jsonFormatter() handles messages without arguments", function () { using _time = new FakeTime(1); From 4742e3ba7726f8dda49de3e7950412986aa76857 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 14 Apr 2025 09:32:32 +1000 Subject: [PATCH 7/8] x --- _tools/lint_plugin_test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 692b7ebebda8..0888243a8746 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -55,7 +55,6 @@ class MyClass { }], ); }); - Deno.test("deno-style-guide/no-top-level-arrow-syntax", { ignore: !Deno.version.deno.startsWith("2"), }, () => { From cd9e5c61146f59b7b48f6a9ed75dfbd3ce1aadac Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 14 Apr 2025 09:32:42 +1000 Subject: [PATCH 8/8] x --- _tools/lint_plugin_test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/_tools/lint_plugin_test.ts b/_tools/lint_plugin_test.ts index 0888243a8746..692b7ebebda8 100644 --- a/_tools/lint_plugin_test.ts +++ b/_tools/lint_plugin_test.ts @@ -55,6 +55,7 @@ class MyClass { }], ); }); + Deno.test("deno-style-guide/no-top-level-arrow-syntax", { ignore: !Deno.version.deno.startsWith("2"), }, () => {