From 33f169beb90814b7f2f62a8c0e3990722ae3db4c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 23 Sep 2024 15:18:52 -0400 Subject: chore: add code generation for @types/deno (#25545) --- tools/jsdoc_checker.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'tools/jsdoc_checker.js') diff --git a/tools/jsdoc_checker.js b/tools/jsdoc_checker.js index 720a8ed8b..241d04273 100755 --- a/tools/jsdoc_checker.js +++ b/tools/jsdoc_checker.js @@ -45,33 +45,39 @@ for (const file of project.getSourceFiles()) { } const parent = node.getFirstAncestorByKind(ts.SyntaxKind.ModuleDeclaration); + const isInterfaceOrType = + node.getKind() === ts.SyntaxKind.InterfaceDeclaration || + node.getKind() === ts.SyntaxKind.TypeAliasDeclaration; if (parent) { if (!node.isExported()) { - errors.push(getErrorPrefix(node) + "export keyword"); + errors.push(getMissingErrorPrefix(node) + "export keyword"); continue; } - } else if (!node.hasDeclareKeyword()) { - errors.push(getErrorPrefix(node) + "declare keyword"); + } else if (!isInterfaceOrType && !node.hasDeclareKeyword()) { + errors.push(getMissingErrorPrefix(node) + "declare keyword"); + continue; + } else if (isInterfaceOrType && node.hasDeclareKeyword()) { + errors.push(getErrorPrefix(node) + "has incorrect declare keyword"); continue; } const jsDoc = node.getFirstChildIfKind(ts.SyntaxKind.JSDoc); if (!jsDoc) { - errors.push(getErrorPrefix(node) + "JSDoc comment"); + errors.push(getMissingErrorPrefix(node) + "JSDoc comment"); continue; } const tags = jsDoc.getTags(); if (!tags.find((tag) => tag.getTagName() === "category")) { - errors.push(getErrorPrefix(node) + "JSDoc @category tag"); + errors.push(getMissingErrorPrefix(node) + "JSDoc @category tag"); continue; } if (unstableFiles.includes(file)) { if (!tags.find((tag) => tag.getTagName() === "experimental")) { - errors.push(getErrorPrefix(node) + "JSDoc @experimental tag"); + errors.push(getMissingErrorPrefix(node) + "JSDoc @experimental tag"); } } } @@ -81,6 +87,10 @@ if (errors.length > 0) { throw new AggregateError(errors); } +function getMissingErrorPrefix(node) { + return getErrorPrefix(node) + `is missing a `; +} + function getErrorPrefix(node) { - return `Symbol at file://${node.getSourceFile().getFilePath()}:${node.getStartLineNumber()} is missing a `; + return `Symbol at file://${node.getSourceFile().getFilePath()}:${node.getStartLineNumber()} `; } -- cgit v1.2.3