From 19e4f6f40af1b07cc1f6c1c028dd6b905b5db66a Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Tue, 15 Mar 2022 07:52:31 +0800 Subject: [PATCH] fix(`require-jsdoc`): allow `TSTypeLiteral` and `TSTypeAliasDeclaration` to have `TSPropertySignature` checks pass through them toward public export for `publicOnly` checks; fixes #852 --- src/exportParser.js | 2 + test/rules/assertions/requireJsdoc.js | 90 +++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/src/exportParser.js b/src/exportParser.js index 02b53febc..94b0563c4 100644 --- a/src/exportParser.js +++ b/src/exportParser.js @@ -456,6 +456,8 @@ const canBeExportedByAncestorType = new Set([ const canExportChildrenType = new Set([ 'TSInterfaceBody', 'TSInterfaceDeclaration', + 'TSTypeLiteral', + 'TSTypeAliasDeclaration', 'ClassDeclaration', 'ClassBody', 'ClassDefinition', diff --git a/test/rules/assertions/requireJsdoc.js b/test/rules/assertions/requireJsdoc.js index 7924dcc73..1e7b0a18e 100644 --- a/test/rules/assertions/requireJsdoc.js +++ b/test/rules/assertions/requireJsdoc.js @@ -3726,6 +3726,96 @@ function quux (foo) { `, parser: require.resolve('@typescript-eslint/parser'), }, + { + code: ` + /** Alpha of all types */ + export type Alpha = { + one: string; + two: number; + }; + `, + errors: [ + { + line: 4, + message: 'Missing JSDoc comment.', + }, + { + line: 5, + message: 'Missing JSDoc comment.', + }, + ], + ignoreReadme: true, + options: [ + { + contexts: [ + 'TSPropertySignature', + ], + publicOnly: true, + }, + ], + output: ` + /** Alpha of all types */ + export type Alpha = { + /** + * + */ + one: string; + /** + * + */ + two: number; + }; + `, + parser: require.resolve('@typescript-eslint/parser'), + }, + { + code: ` + export type Alpha = { + one: string; + two: number; + }; + `, + errors: [ + { + line: 2, + message: 'Missing JSDoc comment.', + }, + { + line: 3, + message: 'Missing JSDoc comment.', + }, + { + line: 4, + message: 'Missing JSDoc comment.', + }, + ], + ignoreReadme: true, + options: [ + { + contexts: [ + 'TSTypeAliasDeclaration', + 'TSPropertySignature', + ], + publicOnly: true, + }, + ], + output: ` + /** + * + */ + export type Alpha = { + /** + * + */ + one: string; + /** + * + */ + two: number; + }; + `, + parser: require.resolve('@typescript-eslint/parser'), + }, ], valid: [ {