Switch to JSDoc imports in scripts (#59068)

This commit is contained in:
Jake Bailey 2024-06-28 13:27:23 -07:00 committed by GitHub
parent 9a23924d55
commit 1b867c52b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 55 additions and 28 deletions

View File

@ -15,6 +15,9 @@ import {
rimraf,
} from "./utils.mjs";
/** @import { CancelToken } from "@esfx/canceltoken" */
void 0;
const mochaJs = path.resolve(findUpRoot(), "node_modules", "mocha", "bin", "_mocha");
export const localBaseline = "tests/baselines/local/";
export const refBaseline = "tests/baselines/reference/";
@ -25,7 +28,7 @@ export const coverageDir = "coverage";
* @param {string} defaultReporter
* @param {boolean} runInParallel
* @param {object} options
* @param {import("@esfx/canceltoken").CancelToken} [options.token]
* @param {CancelToken} [options.token]
* @param {boolean} [options.watching]
*/
export async function runConsoleTests(runJs, defaultReporter, runInParallel, options = {}) {

View File

@ -6,6 +6,9 @@ import fs from "fs";
import JSONC from "jsonc-parser";
import which from "which";
/** @import { CancelToken } from "@esfx/canceltoken" */
void 0;
/**
* Executes the provided command once with the supplied arguments.
* @param {string} cmd
@ -17,7 +20,7 @@ import which from "which";
* @property {boolean} [hidePrompt]
* @property {boolean} [waitForExit=true]
* @property {boolean} [ignoreStdout]
* @property {import("@esfx/canceltoken").CancelToken} [token]
* @property {CancelToken} [token]
*/
export async function exec(cmd, args, options = {}) {
return /**@type {Promise<{exitCode?: number}>}*/ (new Promise((resolve, reject) => {

View File

@ -3,8 +3,10 @@ const { createRule } = require("./utils.cjs");
const ts = require("typescript");
/**
* @typedef {import("@typescript-eslint/utils").TSESTree.CallExpression | import("@typescript-eslint/utils").TSESTree.NewExpression} CallOrNewExpression
* @import { TSESTree } from "@typescript-eslint/utils"
* @typedef {TSESTree.CallExpression | TSESTree.NewExpression} CallOrNewExpression
*/
void 0;
const unset = Symbol();
/**
@ -46,7 +48,7 @@ module.exports = createRule({
/** @type {(name: string) => boolean} */
const isSetOrAssert = name => name.startsWith("set") || name.startsWith("assert");
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
/** @type {(node: TSESTree.Node) => boolean} */
const isTrivia = node => {
if (node.type === AST_NODE_TYPES.Identifier) {
return node.name === "undefined";
@ -101,7 +103,7 @@ module.exports = createRule({
return false;
};
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node, i: number, getSignature: () => ts.Signature | undefined) => void} */
/** @type {(node: TSESTree.Node, i: number, getSignature: () => ts.Signature | undefined) => void} */
const checkArg = (node, i, getSignature) => {
if (!isTrivia(node)) {
return;
@ -123,7 +125,7 @@ module.exports = createRule({
});
const comments = sourceCode.getCommentsBefore(node);
/** @type {import("@typescript-eslint/utils").TSESTree.Comment | undefined} */
/** @type {TSESTree.Comment | undefined} */
const comment = comments[comments.length - 1];
if (!comment || comment.type !== "Block") {

View File

@ -1,6 +1,9 @@
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");
/** @import { TSESTree } from "@typescript-eslint/utils" */
void 0;
module.exports = createRule({
name: "debug-assert",
meta: {
@ -17,14 +20,14 @@ module.exports = createRule({
defaultOptions: [],
create(context) {
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
/** @type {(node: TSESTree.Node) => boolean} */
const isArrowFunction = node => node.type === AST_NODE_TYPES.ArrowFunctionExpression;
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
/** @type {(node: TSESTree.Node) => boolean} */
const isStringLiteral = node => (
(node.type === AST_NODE_TYPES.Literal && typeof node.value === "string") || node.type === AST_NODE_TYPES.TemplateLiteral
);
/** @type {(node: import("@typescript-eslint/utils").TSESTree.MemberExpression) => boolean} */
/** @type {(node: TSESTree.MemberExpression) => boolean} */
const isDebugAssert = node => (
node.object.type === AST_NODE_TYPES.Identifier
&& node.object.name === "Debug"
@ -32,7 +35,7 @@ module.exports = createRule({
&& node.property.name === "assert"
);
/** @type {(node: import("@typescript-eslint/utils").TSESTree.CallExpression) => void} */
/** @type {(node: TSESTree.CallExpression) => void} */
const checkDebugAssert = node => {
const args = node.arguments;
const argsLen = args.length;

View File

@ -1,5 +1,8 @@
const { createRule } = require("./utils.cjs");
/** @import { TSESTree } from "@typescript-eslint/utils" */
void 0;
module.exports = createRule({
name: "js-extensions",
meta: {
@ -18,11 +21,11 @@ module.exports = createRule({
create(context) {
/** @type {(
* node:
* | import("@typescript-eslint/utils").TSESTree.ImportDeclaration
* | import("@typescript-eslint/utils").TSESTree.ExportAllDeclaration
* | import("@typescript-eslint/utils").TSESTree.ExportNamedDeclaration
* | import("@typescript-eslint/utils").TSESTree.TSImportEqualsDeclaration
* | import("@typescript-eslint/utils").TSESTree.TSModuleDeclaration
* | TSESTree.ImportDeclaration
* | TSESTree.ExportAllDeclaration
* | TSESTree.ExportNamedDeclaration
* | TSESTree.TSImportEqualsDeclaration
* | TSESTree.TSModuleDeclaration
* ) => void}
*/
const check = node => {

View File

@ -1,5 +1,8 @@
const { createRule } = require("./utils.cjs");
/** @import { TSESTree } from "@typescript-eslint/utils" */
void 0;
module.exports = createRule({
name: "jsdoc-format",
meta: {
@ -25,17 +28,17 @@ module.exports = createRule({
const atInternal = "@internal";
const jsdocStart = "/**";
/** @type {Map<import("@typescript-eslint/utils").TSESTree.Node, boolean>} */
/** @type {Map<TSESTree.Node, boolean>} */
const isExportedCache = new Map();
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
/** @type {(node: TSESTree.Node) => boolean} */
function isExported(node) {
const exported = isExportedCache.get(node);
if (exported !== undefined) {
return exported;
}
/** @type {import("@typescript-eslint/utils").TSESTree.Node | undefined} */
/** @type {TSESTree.Node | undefined} */
let current = node;
while (current) {
// https://github.com/typescript-eslint/typescript-eslint/blob/e44a1a280f08f9fd0d29f74e5c3e73b7b64a9606/packages/eslint-plugin/src/util/collectUnusedVariables.ts#L440
@ -55,7 +58,7 @@ module.exports = createRule({
return text.startsWith(jsdocStart);
}
/** @type {(c: import("@typescript-eslint/utils").TSESTree.Comment, indexInComment: number) => import("@typescript-eslint/utils").TSESTree.SourceLocation} */
/** @type {(c: TSESTree.Comment, indexInComment: number) => TSESTree.SourceLocation} */
const getAtInternalLoc = (c, indexInComment) => {
return {
start: context.sourceCode.getLocFromIndex(c.range[0] + indexInComment),
@ -63,7 +66,7 @@ module.exports = createRule({
};
};
/** @type {(c: import("@typescript-eslint/utils").TSESTree.Comment) => import("@typescript-eslint/utils").TSESTree.SourceLocation} */
/** @type {(c: TSESTree.Comment) => TSESTree.SourceLocation} */
const getJSDocStartLoc = c => {
return {
start: c.loc.start,
@ -74,7 +77,7 @@ module.exports = createRule({
};
};
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => void} */
/** @type {(node: TSESTree.Node) => void} */
const checkDeclaration = node => {
const blockComments = sourceCode.getCommentsBefore(node).filter(c => c.type === "Block");
if (blockComments.length === 0) {

View File

@ -1,5 +1,8 @@
const { createRule } = require("./utils.cjs");
/** @import { TSESTree } from "@typescript-eslint/utils" */
void 0;
module.exports = createRule({
name: "no-in-operator",
meta: {
@ -16,7 +19,7 @@ module.exports = createRule({
create(context) {
const IN_OPERATOR = "in";
/** @type {(node: import("@typescript-eslint/utils").TSESTree.BinaryExpression) => void} */
/** @type {(node: TSESTree.BinaryExpression) => void} */
const checkInOperator = node => {
if (node.operator === IN_OPERATOR) {
context.report({ messageId: "noInOperatorError", node });

View File

@ -1,6 +1,9 @@
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");
/** @import { TSESTree } from "@typescript-eslint/utils" */
void 0;
module.exports = createRule({
name: "no-keywords",
meta: {
@ -37,12 +40,12 @@ module.exports = createRule({
/** @type {(name: string) => boolean} */
const isKeyword = name => keywords.includes(name);
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Identifier) => void} */
/** @type {(node: TSESTree.Identifier) => void} */
const report = node => {
context.report({ messageId: "noKeywordsError", data: { name: node.name }, node });
};
/** @type {(node: import("@typescript-eslint/utils").TSESTree.ObjectPattern) => void} */
/** @type {(node: TSESTree.ObjectPattern) => void} */
const checkProperties = node => {
node.properties.forEach(property => {
if (
@ -56,7 +59,7 @@ module.exports = createRule({
});
};
/** @type {(node: import("@typescript-eslint/utils").TSESTree.ArrayPattern) => void} */
/** @type {(node: TSESTree.ArrayPattern) => void} */
const checkElements = node => {
node.elements.forEach(element => {
if (
@ -69,7 +72,7 @@ module.exports = createRule({
});
};
/** @type {(node: import("@typescript-eslint/utils").TSESTree.ArrowFunctionExpression | import("@typescript-eslint/utils").TSESTree.FunctionDeclaration | import("@typescript-eslint/utils").TSESTree.FunctionExpression | import("@typescript-eslint/utils").TSESTree.TSMethodSignature | import("@typescript-eslint/utils").TSESTree.TSFunctionType) => void} */
/** @type {(node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.TSMethodSignature | TSESTree.TSFunctionType) => void} */
const checkParams = node => {
if (!node || !node.params || !node.params.length) {
return;

View File

@ -1,7 +1,11 @@
const { AST_NODE_TYPES } = require("@typescript-eslint/utils");
const { createRule } = require("./utils.cjs");
/** @typedef {import("@typescript-eslint/utils").TSESTree.FunctionDeclaration | import("@typescript-eslint/utils").TSESTree.FunctionExpression} FunctionDeclarationOrExpression */
/**
* @import { TSESTree } from "@typescript-eslint/utils"
* @typedef {TSESTree.FunctionDeclaration | TSESTree.FunctionExpression} FunctionDeclarationOrExpression
*/
void 0;
module.exports = createRule({
name: "only-arrow-functions",
@ -32,7 +36,7 @@ module.exports = createRule({
/** @type {(node: FunctionDeclarationOrExpression) => boolean} */
const isThisParameter = node => !!node.params.length && !!node.params.find(param => param.type === AST_NODE_TYPES.Identifier && param.name === "this");
/** @type {(node: import("@typescript-eslint/utils").TSESTree.Node) => boolean} */
/** @type {(node: TSESTree.Node) => boolean} */
const isMethodType = node => {
const types = [
AST_NODE_TYPES.MethodDefinition,