From 6524c312efa77bec149641ea00bcf8ed7bb93fb4 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Fri, 21 Jan 2022 22:47:51 +0800 Subject: [PATCH] fix(`check-types`): allow changing of `Object` in typescript mode; mentioned in #800 --- README.md | 9 ++++++++ src/rules/checkTypes.js | 2 +- test/rules/assertions/checkTypes.js | 32 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9886cfdd1..4eeaa71f1 100644 --- a/README.md +++ b/README.md @@ -5438,6 +5438,15 @@ function b () {} */ // Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}} // Message: Invalid JSDoc @aCustomTag "foo" type "Number"; prefer: ["otherType","anotherType"]. + +/** + * @param {Object[]} foo + */ +function quux (foo) { + +} +// Settings: {"jsdoc":{"mode":"typescript","preferredTypes":{"Object":"object"}}} +// Message: Invalid JSDoc @param "foo" type "Object"; prefer: "object". ```` The following patterns are not considered problems: diff --git a/src/rules/checkTypes.js b/src/rules/checkTypes.js index c63cc0018..96f9d0b5f 100644 --- a/src/rules/checkTypes.js +++ b/src/rules/checkTypes.js @@ -221,7 +221,7 @@ export default iterateJsdoc(({ ]); } else if (!noDefaults && type === 'JsdocTypeName') { for (const strictNativeType of strictNativeTypes) { - if (strictNativeType === 'object' && mode === 'typescript') { + if (strictNativeType === 'object' && mode === 'typescript' && !preferredTypes?.[nodeName]) { continue; } diff --git a/test/rules/assertions/checkTypes.js b/test/rules/assertions/checkTypes.js index 90dcfa6ca..75f8aa109 100644 --- a/test/rules/assertions/checkTypes.js +++ b/test/rules/assertions/checkTypes.js @@ -2129,6 +2129,38 @@ export default { }, }, }, + { + code: ` + /** + * @param {Object[]} foo + */ + function quux (foo) { + + } + `, + errors: [ + { + line: 3, + message: 'Invalid JSDoc @param "foo" type "Object"; prefer: "object".', + }, + ], + output: ` + /** + * @param {object[]} foo + */ + function quux (foo) { + + } + `, + settings: { + jsdoc: { + mode: 'typescript', + preferredTypes: { + Object: 'object', + }, + }, + }, + }, ], valid: [ {