From bda59595c03d7e2b6a596e6864d883d84f04a618 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 19 Dec 2020 08:40:47 +0800 Subject: [PATCH] fix(`no-undefined-types`): allow `this`; fixes #660 --- .README/rules/no-undefined-types.md | 1 + README.md | 12 ++++++++++++ src/rules/noUndefinedTypes.js | 1 + test/rules/assertions/noUndefinedTypes.js | 15 +++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/.README/rules/no-undefined-types.md b/.README/rules/no-undefined-types.md index 2aca370c9..cd9714729 100644 --- a/.README/rules/no-undefined-types.md +++ b/.README/rules/no-undefined-types.md @@ -27,6 +27,7 @@ The following types are always considered defined. `function`, `symbol` - `number`, `bigint`, `NaN`, `Infinity` - `any`, `*` +- `this` - `Array`, `Object`, `RegExp`, `Date`, `Function` Note that preferred types indicated within `settings.jsdoc.preferredTypes` will diff --git a/README.md b/README.md index b0e977371..551e95973 100644 --- a/README.md +++ b/README.md @@ -7026,6 +7026,7 @@ The following types are always considered defined. `function`, `symbol` - `number`, `bigint`, `NaN`, `Infinity` - `any`, `*` +- `this` - `Array`, `Object`, `RegExp`, `Date`, `Function` Note that preferred types indicated within `settings.jsdoc.preferredTypes` will @@ -7563,6 +7564,17 @@ function quux () {} * @type {SomeType} */ // Settings: {"jsdoc":{"structuredTags":{"namepathDefiner":{"name":"namepath-defining"}}}} + +class Test { + /** + * Method. + * + * @returns {this} Return description. + */ + method (): this { + return this; + } +} ```` diff --git a/src/rules/noUndefinedTypes.js b/src/rules/noUndefinedTypes.js index acbbce4ff..d504ceafc 100644 --- a/src/rules/noUndefinedTypes.js +++ b/src/rules/noUndefinedTypes.js @@ -15,6 +15,7 @@ const extraTypes = [ 'function', 'symbol', 'number', 'bigint', 'NaN', 'Infinity', 'any', '*', + 'this', 'Array', 'Object', 'RegExp', 'Date', 'Function', ]; diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index e2ab3a784..bcf1acf13 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -938,5 +938,20 @@ export default { }, }, }, + { + code: ` + class Test { + /** + * Method. + * + * @returns {this} Return description. + */ + method (): this { + return this; + } + } + `, + parser: require.resolve('@typescript-eslint/parser'), + }, ], };