From 5a79d3fc1d4368612d98a567739f19053f0eca3a Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Tue, 6 Feb 2024 10:04:42 -0700 Subject: [PATCH] fix(informative-docs): check named export declarations: fixes #1198 --- docs/rules/informative-docs.md | 9 +++++++++ src/rules/informativeDocs.js | 6 ++++++ test/rules/assertions/informativeDocs.js | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/docs/rules/informative-docs.md b/docs/rules/informative-docs.md index 2d597b5df..058ba5414 100644 --- a/docs/rules/informative-docs.md +++ b/docs/rules/informative-docs.md @@ -254,6 +254,15 @@ function takesOne(param) {} let emoji; // "jsdoc/informative-docs": ["error"|"warn", {"aliases":{"emoji":["smiley","winkey"]}}] // Message: This description only repeats the name it describes. + +/** + * package name from path + */ +export function packageNameFromPath(path) { + const base = basename(path); + return /^vd+(.d+)?$/.exec(base) || /^tsd.d/.exec(base) ? basename(dirname(path)) : base; +} +// Message: This description only repeats the name it describes. ```` diff --git a/src/rules/informativeDocs.js b/src/rules/informativeDocs.js index 03bd4c4ca..8dbef5b8b 100644 --- a/src/rules/informativeDocs.js +++ b/src/rules/informativeDocs.js @@ -38,6 +38,12 @@ const getNamesFromNode = (node) => { (node.key), ), ]; + + case 'ExportNamedDeclaration': + return getNamesFromNode( + /** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */ + (node).declaration + ); case 'ClassDeclaration': case 'ClassExpression': case 'FunctionDeclaration': diff --git a/test/rules/assertions/informativeDocs.js b/test/rules/assertions/informativeDocs.js index 5dbb8f27e..3a1ec79f9 100644 --- a/test/rules/assertions/informativeDocs.js +++ b/test/rules/assertions/informativeDocs.js @@ -501,6 +501,23 @@ export default { }, ], }, + { + code: ` + /** + * package name from path + */ + export function packageNameFromPath(path) { + const base = basename(path); + return /^v\d+(\.\d+)?$/.exec(base) || /^ts\d\.\d/.exec(base) ? basename(dirname(path)) : base; + } + `, + errors: [ + { + line: 2, + message: 'This description only repeats the name it describes.', + }, + ], + } ], valid: [ {