From e9a9b74ae49d198b2c5afcf304c5928f16867e7a Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Tue, 6 Feb 2024 10:22:28 -0700 Subject: [PATCH] fix(informative-docs): check default named declaration --- docs/rules/informative-docs.md | 9 +++++++++ src/rules/informativeDocs.js | 1 + test/rules/assertions/informativeDocs.js | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/docs/rules/informative-docs.md b/docs/rules/informative-docs.md index 058ba5414..027d4e1fa 100644 --- a/docs/rules/informative-docs.md +++ b/docs/rules/informative-docs.md @@ -263,6 +263,15 @@ export function packageNameFromPath(path) { return /^vd+(.d+)?$/.exec(base) || /^tsd.d/.exec(base) ? basename(dirname(path)) : base; } // Message: This description only repeats the name it describes. + +/** + * package name from path + */ +export default 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 8dbef5b8b..7ccbff88a 100644 --- a/src/rules/informativeDocs.js +++ b/src/rules/informativeDocs.js @@ -39,6 +39,7 @@ const getNamesFromNode = (node) => { ), ]; + case 'ExportDefaultDeclaration': case 'ExportNamedDeclaration': return getNamesFromNode( /** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */ diff --git a/test/rules/assertions/informativeDocs.js b/test/rules/assertions/informativeDocs.js index 3a1ec79f9..c9fa78a10 100644 --- a/test/rules/assertions/informativeDocs.js +++ b/test/rules/assertions/informativeDocs.js @@ -517,6 +517,23 @@ export default { message: 'This description only repeats the name it describes.', }, ], + }, + { + code: ` + /** + * package name from path + */ + export default 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: [