gund / eslint-plugin-deprecation

ESLint rule that reports usage of deprecated code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jsdoc/tsdoc not parsed correctly

alumni opened this issue · comments

Seems that the deprecation message is shown as [object Object], after upgrading TypeScript 4.3:

image

I am also experiencing this issue.

I am also seeing this issue.

I think it breaks because of this change in the typescript AST: microsoft/TypeScript#41877

Changing the implementation of getJsDocDeprecation to something like:

function getJsDocDeprecation(tags: ts.JSDocTagInfo[]) {
  for (const tag of tags) {
    if (tag.name === 'deprecated') {
      let reason = tag.text || ''
      if (Array.isArray(tag.text) && tag.text.length > 0) {
        reason = tag.text[0].text || ''
      }
      return { reason: reason }
    }
  }
  return undefined
}

Should fix the issue.

For now, I made the following patch-package

diff --git a/node_modules/eslint-plugin-deprecation/dist/rules/deprecation.js b/node_modules/eslint-plugin-deprecation/dist/rules/deprecation.js
index 606774f..8a1e478 100644
--- a/node_modules/eslint-plugin-deprecation/dist/rules/deprecation.js
+++ b/node_modules/eslint-plugin-deprecation/dist/rules/deprecation.js
@@ -230,13 +230,17 @@ function isCallExpression(node, callee) {
     return false;
 }
 function getJsDocDeprecation(tags) {
-    for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
-        var tag = tags_1[_i];
-        if (tag.name === 'deprecated') {
-            return { reason: tag.text || '' };
+  for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
+      var tag = tags_1[_i];
+      if (tag.name === 'deprecated') {
+        let reason = tag.text || '';
+        if(Array.isArray(tag.text) && tag.text.length > 0) {
+          reason = tag.text[0].text || ''
         }
-    }
-    return undefined;
+        return { reason: reason };
+      }
+  }
+  return undefined;
 }
 function isFunction(symbol) {
     var declarations = symbol.declarations;

While we are waiting for these things to be merged I created a quick and dirty release with #33 and #38.

Just add the following to your package.json:

"eslint-plugin-deprecation": "https://github.com/jleider/eslint-plugin-deprecation#v1.3.0"

The fix is being prepared in #35

Released in v1.3.1!