Skip to content

Commit 5a79d3f

Browse files
committed
fix(informative-docs): check named export declarations: fixes #1198
1 parent 207bc74 commit 5a79d3f

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/rules/informative-docs.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ function takesOne(param) {}
254254
let emoji;
255255
// "jsdoc/informative-docs": ["error"|"warn", {"aliases":{"emoji":["smiley","winkey"]}}]
256256
// Message: This description only repeats the name it describes.
257+
258+
/**
259+
* package name from path
260+
*/
261+
export function packageNameFromPath(path) {
262+
const base = basename(path);
263+
return /^vd+(.d+)?$/.exec(base) || /^tsd.d/.exec(base) ? basename(dirname(path)) : base;
264+
}
265+
// Message: This description only repeats the name it describes.
257266
````
258267

259268

src/rules/informativeDocs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ const getNamesFromNode = (node) => {
3838
(node.key),
3939
),
4040
];
41+
42+
case 'ExportNamedDeclaration':
43+
return getNamesFromNode(
44+
/** @type {import('@typescript-eslint/types').TSESTree.ExportNamedDeclaration} */
45+
(node).declaration
46+
);
4147
case 'ClassDeclaration':
4248
case 'ClassExpression':
4349
case 'FunctionDeclaration':

test/rules/assertions/informativeDocs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,23 @@ export default {
501501
},
502502
],
503503
},
504+
{
505+
code: `
506+
/**
507+
* package name from path
508+
*/
509+
export function packageNameFromPath(path) {
510+
const base = basename(path);
511+
return /^v\d+(\.\d+)?$/.exec(base) || /^ts\d\.\d/.exec(base) ? basename(dirname(path)) : base;
512+
}
513+
`,
514+
errors: [
515+
{
516+
line: 2,
517+
message: 'This description only repeats the name it describes.',
518+
},
519+
],
520+
}
504521
],
505522
valid: [
506523
{

0 commit comments

Comments
 (0)