Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
deno task test
deno task test:with-unsafe-proto

- name: Run tools tests
run: deno task test:tools
if: matrix.deno == 'canary'

- name: Run timezone-dependent tests
run: |
TZ=Australia/Sydney deno test datetime
Expand Down
30 changes: 17 additions & 13 deletions _tools/lint_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2026 the Deno authors. MIT license.
// @ts-nocheck Deno.lint namespace does not pass type checking in Deno 1.x
// Deno.lint namespace does not pass type checking in Deno 1.x

/**
* Lint plugin that enforces the
Expand Down Expand Up @@ -264,15 +264,16 @@ export default {
const value = argument.value;
if (typeof value !== "string") return;

if (value[0] !== value[0].toUpperCase()) {
const char = value[0] as string;
if (char !== char.toUpperCase()) {
context.report({
node: argument,
message: "Error message starts with a lowercase.",
hint:
"Capitalize the error message. See https://docs.deno.com/runtime/contributing/style_guide/#error-messages for more details.",
fix(fixer) {
const newValue = argument.raw.at(0) +
value[0].toUpperCase() +
char.toUpperCase() +
value.slice(1) +
argument.raw.at(-1);
return fixer.replaceText(argument, newValue);
Expand Down Expand Up @@ -338,26 +339,29 @@ export default {

return {
ExportNamedDeclaration(node) {
if (node.declaration?.type !== "FunctionDeclaration") return;
const { params, id } = node.declaration;
const { declaration } = node;
if (declaration?.type !== "FunctionDeclaration") return;
const { params, id } = declaration;
if (params.length < 3) return;
if (params.length === 3) {
const param = params.at(-1)!;

switch (param.type) {
case "Identifier":
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<T, "foo" | "bar"> as 3rd argument is valid
if (
param.typeAnnotation?.typeAnnotation?.typeName?.name ===
"Pick"
) return;
const typeAnn = param.typeAnnotation?.typeAnnotation;
const typeRef = typeAnn as Deno.lint.TSTypeReference;
const typeName = typeRef?.typeName as Deno.lint.Identifier;
if (typeName?.name === "Pick") return;
break;
}
case "AssignmentPattern": {
if (param.right.type === "ObjectExpression") return;
break;
Expand Down Expand Up @@ -387,22 +391,22 @@ export default {
create(context) {
// Skip checking this rule in the ignore_comments.ts file to avoid
// testing of other rules being affected.
if (context.filename === "ignore_comments.ts") return;
if (context.filename === "ignore_comments.ts") return {};
const comments = context.sourceCode.getAllComments();
// Only check the first 6 comments, for performance
const node = comments.slice(0, 6).find((comment) =>
comment.value.includes(COPYRIGHT_NOTICE) && comment.type === "Line"
);
if (!node) {
context.report({
node,
range: [0, 0],
message: "Missing copyright notice.",
hint:
`Add a copyright notice at the top of the file: // ${COPYRIGHT_NOTICE}`,
});
}
return {};
},
},
},
} satisfies Deno.lint.Plugin;
} as Deno.lint.Plugin;
4 changes: 2 additions & 2 deletions _tools/lint_plugin_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2026 the Deno authors. MIT license.
// @ts-nocheck Deno.lint namespace does not pass type checking in Deno 1.x
// Deno.lint namespace does not pass type checking in Deno 1.x

import { assertEquals } from "@std/assert/equals";
import lintPlugin, { COPYRIGHT_NOTICE } from "./lint_plugin.ts";
Expand Down Expand Up @@ -240,7 +240,7 @@ enum enumName {
message: "Interface name 'interfaceName' is not PascalCase.",
range: [264, 277],
},
],
] as unknown as Deno.lint.Diagnostic[],
);
});

Expand Down
6 changes: 3 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"importMap": "./import_map.json",
"unstable": ["webgpu", "fs"],
"tasks": {
"test": "deno test --allow-all --parallel --trace-leaks --coverage --doc --clean",
"test:with-unsafe-proto": "deno test --unstable-unsafe-proto --allow-all --parallel --trace-leaks --coverage --doc --clean",

"test": "deno test -A --parallel --trace-leaks --coverage --doc --clean --ignore=_tools/",
"test:with-unsafe-proto": "deno test --unstable-unsafe-proto --no-check -A --parallel --doc --ignore=_tools/",
"test:tools": "deno test -A --doc _tools/",
"test:browser": "git grep --name-only \"This module is browser compatible.\" | grep -v deno.json | grep -v .github/workflows | grep -v _tools | grep -v encoding/README.md | grep -v media_types/vendor/update.ts | xargs deno check --config browser-compat.tsconfig.json",
"test:node": "(cd _tools/node_test_runner && npm install) && node --import ./_tools/node_test_runner/register_deno_shim.mjs ./_tools/node_test_runner/run_test.mjs",
"lint:deprecations": "deno run --allow-read --allow-net --allow-env ./_tools/check_deprecation.ts",
Expand Down