Skip to content

Commit

Permalink
chore: simplify deprecation notice check (#4577)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Apr 17, 2024
1 parent fe9b295 commit 3f9d4a8
Show file tree
Hide file tree
Showing 38 changed files with 133 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ and [architecture guide](./ARCHITECTURE.md) before contributing.
```ts
// /sub/foo.ts
/**
* @deprecated (will be removed in 0.215.0) Use {@linkcode bar} instead.
* @deprecated This will be removed in 0.215.0. Use {@linkcode bar} instead.
*/
export function foo() {}
```
Expand Down
155 changes: 33 additions & 122 deletions _tools/check_deprecation.ts
Original file line number Diff line number Diff line change
@@ -1,137 +1,48 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/**
* Checks whether all deprecated tags have a message.
*
* @example
* ```sh
* deno task lint:deprecations
* ```
*/

import { VERSION } from "../version.ts";
import * as semver from "../semver/mod.ts";
import * as colors from "../fmt/colors.ts";
import { doc } from "deno_doc";
import { walk } from "../fs/walk.ts";
import { toFileUrl } from "../path/mod.ts";
import { toFileUrl } from "../path/to_file_url.ts";

const ROOT = new URL("../", import.meta.url);

const FAIL_FAST = Deno.args.includes("--fail-fast");
let failed = false;

const DEPRECATION_IN_FORMAT_REGEX =
/^\(will be removed in (?<version>\d+\.\d+\.\d+)\)/;
const DEPRECATION_AFTER_FORMAT_REGEX =
/^\(will be removed after (?<version>\d+\.\d+\.\d+)\)/;
const iter = walk(ROOT, {
includeDirs: false,
exts: [".ts"],
skip: [
/.git/,
/(\/|\\)_/,
/_test.ts$/,
],
});

let shouldFail = false;

// add three minor version to current version
const DEFAULT_DEPRECATED_VERSION = semver.increment(
semver.increment(
semver.increment(
semver.parse(VERSION),
"minor",
)!,
"minor",
)!,
"minor",
);

const DEPRECATION_IN_FORMAT =
`(will be removed in ${DEFAULT_DEPRECATED_VERSION})`;

for await (
const { path } of walk(ROOT, {
includeDirs: false,
exts: [".mjs", ".js", ".ts"],
skip: [
/\.git$/,
/dotenv(\/|\\)testdata$/,
/fs(\/|\\)testdata$/,
/http(\/|\\)testdata$/,
/http(\/|\\)_negotiation$/,
/crypto(\/|\\)_benches$/,
/crypto(\/|\\)_wasm$/,
/encoding(\/|\\)_yaml$/,
/encoding(\/|\\)_toml$/,
/console$/,
/_tools$/,
/_util$/,
/docs$/,
/permissions/,
],
})
) {
// deno_doc only takes urls.
const url = toFileUrl(path);
for await (const entry of iter) {
const url = toFileUrl(entry.path);
const docs = await doc(url.href);

for (const d of docs) {
const tags = d.jsDoc?.tags;
if (tags) {
for (const tag of tags) {
switch (tag.kind) {
case "deprecated": {
const message = tag.doc;
if (!message) {
console.error(
colors.red("Error"),
`${
colors.bold("@deprecated")
} tag must have a version: ${path}:${d.location.line}`,
);
shouldFail = true;
if (FAIL_FAST) Deno.exit(1);
continue;
}
const { version: afterVersion } =
DEPRECATION_AFTER_FORMAT_REGEX.exec(message)?.groups || {};

if (afterVersion) {
if (
semver.lessThan(
semver.parse(afterVersion),
semver.parse(VERSION),
)
) {
console.warn(
colors.yellow("Warn"),
`${
colors.bold("@deprecated")
} tag is expired and export should be removed: ${path}:${d.location.line}`,
);
}
continue;
}

const { version: inVersion } =
DEPRECATION_IN_FORMAT_REGEX.exec(message)?.groups || {};
if (!inVersion) {
console.error(
colors.red("Error"),
`${
colors.bold("@deprecated")
} tag version is missing. Append '${DEPRECATION_IN_FORMAT}' after @deprecated tag: ${path}:${d.location.line}`,
);
shouldFail = true;
if (FAIL_FAST) Deno.exit(1);
continue;
}

if (
!semver.greaterThan(
semver.parse(inVersion),
semver.parse(VERSION),
)
) {
console.error(
colors.red("Error"),
`${
colors.bold("@deprecated")
} tag is expired and export must be removed: ${path}:${d.location.line}`,
);
if (FAIL_FAST) Deno.exit(1);
shouldFail = true;
continue;
}
}
}
for (const document of docs) {
const tags = document.jsDoc?.tags;
if (!tags) continue;
for (const tag of tags) {
if (tag.kind !== "deprecated") continue;
if (tag.doc === undefined) {
console.log(
`%c@deprecated tag with JSDoc block must have a message: ${document.location.filename}:${document.location.line}`,
"color: yellow",
);
failed = true;
}
}
}
}

if (shouldFail) Deno.exit(1);
if (failed) Deno.exit(1);
8 changes: 5 additions & 3 deletions crypto/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,23 @@ const stdCrypto: StdCrypto = ((x) => x)({
/**
* A FNV (Fowler/Noll/Vo) digest algorithm name supported by std/crypto.
*
* @deprecated (will be removed in 1.0.0)
* @deprecated This will be removed in 1.0.0.
*/
export type FNVAlgorithms = "FNV32" | "FNV32A" | "FNV64" | "FNV64A";

/**
* Digest algorithm names supported by std/crypto with a Wasm implementation.
*
* @deprecated (will be removed in 1.0.0) Consider using {@linkcode DIGEST_ALGORITHM_NAMES} instead.
* @deprecated This will be removed in 1.0.0. Use
* {@linkcode DIGEST_ALGORITHM_NAMES} instead.
*/
export const wasmDigestAlgorithms = DIGEST_ALGORITHM_NAMES;

/**
* A digest algorithm name supported by std/crypto with a Wasm implementation.
*
* @deprecated (will be removed in 1.0.0) Consider using {@linkcode DigestAlgorithmName} instead.
* @deprecated This will be removed in 1.0.0. Use
* {@linkcode DigestAlgorithmName} instead.
*/
export type WasmDigestAlgorithm = DigestAlgorithmName;

Expand Down
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"imports": {
"https://deno.land/std@$STD_VERSION/": "./",
"@deno/graph": "jsr:@deno/graph@^0.70",
"deno_doc": "https://deno.land/x/deno_doc@0.73.0/mod.ts",
"deno_doc": "https://deno.land/x/deno_doc@0.123.1/mod.ts",
"npm:/typescript": "npm:typescript@5.4.4",
"automation/": "https://raw.githubusercontent.com/denoland/automation/0.10.0/"
},
"tasks": {
"test": "RUST_BACKTRACE=1 deno test --unstable-http --unstable-webgpu --doc --allow-all --parallel --coverage --trace-leaks",
"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 | xargs deno check --config browser-compat.tsconfig.json",
"fmt:licence-headers": "deno run --allow-read --allow-write ./_tools/check_licence.ts",
"lint:deprecations": "deno run --allow-read --allow-net --allow-env=HOME ./_tools/check_deprecation.ts",
"lint:deprecations": "deno run --allow-read --allow-net --allow-env ./_tools/check_deprecation.ts",
"lint:doc-imports": "deno run --allow-env --allow-read ./_tools/check_doc_imports.ts",
"lint:circular": "deno run --allow-env --allow-read --allow-net=deno.land,jsr.io ./_tools/check_circular_submodule_dependencies.ts",
"lint:mod-exports": "deno run --allow-env --allow-read ./_tools/check_mod_exports.ts",
Expand Down
7 changes: 4 additions & 3 deletions encoding/varint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const U64_VIEW = new BigUint64Array(AB);
* decode(buf); // [ 300n, 2 ];
* ```
*
* @deprecated (will be removed in 1.0.0) Use {@linkcode decodeVarint} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode decodeVarint}
* instead.
*/
export function decode(buf: Uint8Array, offset = 0): [bigint, number] {
return decodeVarint(buf, offset);
Expand Down Expand Up @@ -176,7 +177,7 @@ export function decodeVarint(buf: Uint8Array, offset = 0): [bigint, number] {
* decode32(buf); // [ 300, 2 ];
* ```
*
* @deprecated (will be removed in 1.0.0) Use {@linkcode decodeVarint32}
* @deprecated This will be removed in 1.0.0. Use {@linkcode decodeVarint32}
* instead.
*/
export function decode32(buf: Uint8Array, offset = 0): [number, number] {
Expand Down Expand Up @@ -248,7 +249,7 @@ export function decodeVarint32(buf: Uint8Array, offset = 0): [number, number] {
* encode(42n, buf); // [ Uint8Array(1) [ 42 ], 1 ];
* ```
*
* @deprecated (will be removed in 1.0.0) Use {@linkcode encodeVarint} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode encodeVarint} instead.
*/
export function encode(
num: bigint | number,
Expand Down
8 changes: 4 additions & 4 deletions flags/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* console.dir(parse(Deno.args));
* ```
*
* @deprecated (will be removed in 1.0.0) Import from
* @deprecated This will be removed in 1.0.0. Import from
* {@link https://deno.land/std/cli/parse_args.ts} instead.
*
* @module
Expand Down Expand Up @@ -234,7 +234,7 @@ type ValueOf<TValue> = TValue[keyof TValue];
/**
* The value returned from `parse`.
*
* @deprecated (will be removed in 1.0.0) Import from
* @deprecated This will be removed in 1.0.0. Import from
* {@link https://deno.land/std/cli/parse_args.ts} instead.
*/
export type Args<
Expand All @@ -261,7 +261,7 @@ type DoubleDash = {
/**
* The options for the `parse` call.
*
* @deprecated (will be removed in 1.0.0) Import from
* @deprecated This will be removed in 1.0.0. Import from
* {@link https://deno.land/std/cli/parse_args.ts} instead.
*/
export interface ParseOptions<
Expand Down Expand Up @@ -423,7 +423,7 @@ function hasKey(obj: NestedMapping, keys: string[]): boolean {
* // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] }
* ```
*
* @deprecated (will be removed in 1.0.0) Use
* @deprecated This will be removed in 1.0.0. Use
* {@linkcode https://deno.land/std/cli/parse_args.ts?s=parseArgs | parseArgs}
* instead.
*/
Expand Down
2 changes: 1 addition & 1 deletion fmt/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ const ANSI_PATTERN = new RegExp(
* Remove ANSI escape codes from the string.
* @param string to remove ANSI escape codes from
*
* @deprecated (will be removed in 1.0.0) Use {@linkcode stripAnsiCode} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode stripAnsiCode} instead.
*/
export function stripColor(string: string): string {
return stripAnsiCode(string);
Expand Down
20 changes: 10 additions & 10 deletions http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MAX_ACCEPT_BACKOFF_DELAY = 1000;
/**
* Information about the connection a request arrived on.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.ServeHandlerInfo} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.ServeHandlerInfo} instead.
*/
export interface ConnInfo {
/** The local address of the connection. */
Expand All @@ -36,7 +36,7 @@ export interface ConnInfo {
* of the error is isolated to the individual request. It will catch the error
* and close the underlying connection.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.ServeHandler} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.ServeHandler} instead.
*/
export type Handler = (
request: Request,
Expand All @@ -46,7 +46,7 @@ export type Handler = (
/**
* Options for running an HTTP server.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.ServeInit} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.ServeInit} instead.
*/
export interface ServerInit extends Partial<Deno.ListenOptions> {
/** The handler to invoke for individual HTTP requests. */
Expand All @@ -63,7 +63,7 @@ export interface ServerInit extends Partial<Deno.ListenOptions> {
/**
* Used to construct an HTTP server.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.serve} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.serve} instead.
*/
export class Server {
#port?: number;
Expand Down Expand Up @@ -501,7 +501,7 @@ export class Server {
/**
* Additional serve options.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.ServeInit} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.ServeInit} instead.
*/
export interface ServeInit extends Partial<Deno.ListenOptions> {
/** An AbortSignal to close the server and all connections. */
Expand All @@ -517,7 +517,7 @@ export interface ServeInit extends Partial<Deno.ListenOptions> {
/**
* Additional serve listener options.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.ServeOptions} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.ServeOptions} instead.
*/
export interface ServeListenerOptions {
/** An AbortSignal to close the server and all connections. */
Expand Down Expand Up @@ -554,7 +554,7 @@ export interface ServeListenerOptions {
* @param handler The handler for individual HTTP requests.
* @param options Optional serve options.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.serve} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.serve} instead.
*/
export async function serveListener(
listener: Deno.Listener,
Expand Down Expand Up @@ -622,7 +622,7 @@ function hostnameForDisplay(hostname: string) {
* @param handler The handler for individual HTTP requests.
* @param options The options. See `ServeInit` documentation for details.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.serve} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.serve} instead.
*/
export async function serve(
handler: Handler,
Expand Down Expand Up @@ -667,7 +667,7 @@ export async function serve(
/**
* Initialization parameters for {@linkcode serveTls}.
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.ServeTlsOptions} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.ServeTlsOptions} instead.
*/
export interface ServeTlsInit extends ServeInit {
/** Server private key in PEM format */
Expand Down Expand Up @@ -742,7 +742,7 @@ export interface ServeTlsInit extends ServeInit {
* @param options The options. See `ServeTlsInit` documentation for details.
* @returns
*
* @deprecated (will be removed after 1.0.0) Use {@linkcode Deno.serve} instead.
* @deprecated This will be removed in 1.0.0. Use {@linkcode Deno.serve} instead.
*/
export async function serveTls(
handler: Handler,
Expand Down
Loading

0 comments on commit 3f9d4a8

Please sign in to comment.