Skip to content

Commit

Permalink
fix(informative-docs): check named export declarations: fixes #1198
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Feb 6, 2024
1 parent 207bc74 commit 5a79d3f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/rules/informative-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
````


Expand Down
6 changes: 6 additions & 0 deletions src/rules/informativeDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
17 changes: 17 additions & 0 deletions test/rules/assertions/informativeDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down

0 comments on commit 5a79d3f

Please sign in to comment.