Skip to content

Commit

Permalink
fix(check-types): allow changing of Object in typescript mode; me…
Browse files Browse the repository at this point in the history
…ntioned in #800
  • Loading branch information
brettz9 committed Jan 21, 2022
1 parent 873228a commit 6524c31
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/rules/checkTypes.js
Expand Up @@ -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;
}

Expand Down
32 changes: 32 additions & 0 deletions test/rules/assertions/checkTypes.js
Expand Up @@ -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: [
{
Expand Down

0 comments on commit 6524c31

Please sign in to comment.