-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify deprecation notice check (#4577)
- Loading branch information
Showing
38 changed files
with
133 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.