Skip to content

Commit

Permalink
fix(check-types): proper use of optional chaining; fixes #861
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Mar 28, 2022
1 parent d11d271 commit 7dbdd9f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -5576,6 +5576,18 @@ function quux (foo) {
}
// Settings: {"jsdoc":{"mode":"typescript"}}
// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object<>".

/**
*
* @param {Object} param
* @return {Object | String}
*/
function abc(param) {
if (param.a)
return {};
return 'abc';
}
// Message: Invalid JSDoc @param "param" type "Object"; prefer: "object".
````

The following patterns are not considered problems:
Expand Down
4 changes: 2 additions & 2 deletions src/rules/checkTypes.js
Expand Up @@ -206,8 +206,8 @@ export default iterateJsdoc(({
// `unifyParentAndChildTypeChecks`) and we don't want
// `object<>` given TypeScript issue https://github.com/microsoft/TypeScript/issues/20555
parentNode?.elements.length && (
parentNode?.left.type === 'JsdocTypeName' &&
parentNode?.left.value === 'Object'
parentNode?.left?.type === 'JsdocTypeName' &&
parentNode?.left?.value === 'Object'
)
)
) {
Expand Down
40 changes: 40 additions & 0 deletions test/rules/assertions/checkTypes.js
Expand Up @@ -2356,6 +2356,46 @@ export default {
},
},
},
{
code: `
/**
*
* @param {Object} param
* @return {Object | String}
*/
function abc(param) {
if (param.a)
return {};
return 'abc';
}
`,
errors: [
{
line: 4,
message: 'Invalid JSDoc @param "param" type "Object"; prefer: "object".',
},
{
line: 5,
message: 'Invalid JSDoc @return type "Object"; prefer: "object".',
},
{
line: 5,
message: 'Invalid JSDoc @return type "String"; prefer: "string".',
},
],
output: `
/**
*
* @param {object} param
* @return {Object | String}
*/
function abc(param) {
if (param.a)
return {};
return 'abc';
}
`,
},
],
valid: [
{
Expand Down

0 comments on commit 7dbdd9f

Please sign in to comment.