Skip to content

Commit 757d97a

Browse files
committed
fix(require-jsdoc): check above export for named exports; fixes #526
1 parent 23b03df commit 757d97a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8053,6 +8053,10 @@ const hello = name => {
80538053
};
80548054
// Options: [{"require":{"ArrowFunctionExpression":true,"FunctionDeclaration":false}}]
80558055
// Message: Missing JSDoc comment.
8056+
8057+
export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
8058+
// Options: [{"require":{"ArrowFunctionExpression":true,"FunctionDeclaration":false}}]
8059+
// Message: Missing JSDoc comment.
80568060
````
80578061
80588062
The following patterns are not considered problems:

src/eslint/getJSDocComment.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ const getReducedASTNode = function (node, sourceCode) {
154154
}
155155
}
156156

157-
if (parent && parent.type !== 'FunctionDeclaration' && parent.type !== 'Program') {
157+
if (parent) {
158+
if (parent.parent.type === 'ExportNamedDeclaration') {
159+
return parent.parent;
160+
}
161+
158162
return parent;
159163
}
160164
}

test/rules/assertions/requireJsdoc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,34 @@ export default {
13841384
};
13851385
`,
13861386
},
1387+
{
1388+
code: `
1389+
export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
1390+
`,
1391+
errors: [
1392+
{
1393+
message: 'Missing JSDoc comment.',
1394+
},
1395+
],
1396+
options: [
1397+
{
1398+
require: {
1399+
ArrowFunctionExpression: true,
1400+
FunctionDeclaration: false,
1401+
},
1402+
},
1403+
],
1404+
output: `
1405+
/**
1406+
*
1407+
*/
1408+
export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
1409+
`,
1410+
parser: require.resolve('@typescript-eslint/parser'),
1411+
parserOptions: {
1412+
sourceType: 'module',
1413+
},
1414+
},
13871415
],
13881416
valid: [{
13891417
code: `

0 commit comments

Comments
 (0)