Skip to content

Commit 7015225

Browse files
committed
fix: false positive with optional chaining
fixes #182
1 parent e9aa652 commit 7015225

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,10 @@ function quux (foo) {
39023902

39033903
}
39043904
// Settings: {"jsdoc":{"ignorePrivate":true}}
3905+
3906+
// issue 182: optional chaining
3907+
/** @const {boolean} test */
3908+
const test = something?.find(_ => _)
39053909
````
39063910

39073911

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
1818
"@babel/preset-env": "^7.4.5",
1919
"@babel/register": "^7.4.4",
20+
"babel-eslint": "^10.0.1",
2021
"babel-plugin-add-module-exports": "^1.0.2",
2122
"babel-plugin-istanbul": "^5.1.4",
2223
"chai": "^4.2.0",

src/eslint/getJSDocComment.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ const getJSDocComment = function (sourceCode, node) {
7171

7272
case 'ArrowFunctionExpression':
7373
case 'FunctionExpression':
74-
if (parent.type !== 'CallExpression' && parent.type !== 'NewExpression') {
74+
if (
75+
parent.type !== 'CallExpression' &&
76+
parent.type !== 'OptionalCallExpression' &&
77+
parent.type !== 'NewExpression'
78+
) {
7579
while (
7680
!sourceCode.getCommentsBefore(parent).length &&
7781
!/Function/u.test(parent.type) &&

test/rules/assertions/requireParam.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ export default {
559559
ignorePrivate: true
560560
}
561561
}
562+
},
563+
{
564+
code: `
565+
// issue 182: optional chaining
566+
/** @const {boolean} test */
567+
const test = something?.find(_ => _)
568+
`,
569+
parser: 'babel-eslint'
562570
}
563571
]
564572
};

0 commit comments

Comments
 (0)