Skip to content

Commit

Permalink
fix(require-jsdoc): allow TSInterfaceDeclaration to find jsdoc bl…
Browse files Browse the repository at this point in the history
…ock preceding export; fixes #385
  • Loading branch information
brettz9 committed Sep 26, 2019
1 parent b7e93f0 commit c523384
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5647,6 +5647,28 @@ function quux () {
}
export default quux;
// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]

/**
* This example interface is great!
*/
export interface Example {
/**
* My super test string!
*/
test: string
}
// Options: [{"contexts":["TSInterfaceDeclaration"]}]

/**
* This example interface is great!
*/
interface Example {
/**
* My super test string!
*/
test: string
}
// Options: [{"contexts":["TSInterfaceDeclaration"]}]
````


Expand Down
7 changes: 3 additions & 4 deletions src/eslint/getJSDocComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ const getJSDocComment = function (sourceCode, node, settings) {

return null;
};
let parent = node.parent;
let {parent} = node;

switch (node.type) {
case 'TSInterfaceDeclaration':
case 'ClassDeclaration':
case 'FunctionDeclaration':
return findJSDocComment(looksLikeExport(parent) ? parent : node);
Expand All @@ -74,9 +75,7 @@ const getJSDocComment = function (sourceCode, node, settings) {
case 'ArrowFunctionExpression':
case 'FunctionExpression':
if (
parent.type !== 'CallExpression' &&
parent.type !== 'OptionalCallExpression' &&
parent.type !== 'NewExpression'
!['CallExpression', 'OptionalCallExpression', 'NewExpression'].includes(parent.type)
) {
while (
!sourceCode.getCommentsBefore(parent).length &&
Expand Down
50 changes: 49 additions & 1 deletion test/rules/assertions/requireJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2182,5 +2182,53 @@ export default {
parserOptions: {
sourceType: 'module',
},
}],
}, {
code: `
/**
* This example interface is great!
*/
export interface Example {
/**
* My super test string!
*/
test: string
}
`,
options: [
{
contexts: [
'TSInterfaceDeclaration',
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
},
},
{
code: `
/**
* This example interface is great!
*/
interface Example {
/**
* My super test string!
*/
test: string
}
`,
options: [
{
contexts: [
'TSInterfaceDeclaration',
],
},
],
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
},
},
],
};

0 comments on commit c523384

Please sign in to comment.