Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit e3c3c47

Browse files
committed
fix: print deprecation reason correctly on ts 4.3+
1 parent a03446f commit e3c3c47

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/rules/deprecation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '@typescript-eslint/experimental-utils';
2121
import { isReassignmentTarget } from 'tsutils';
2222
import * as ts from 'typescript';
23+
import { stringifyJSDocTagInfoText } from '../utils/stringifyJSDocTagInfoText';
2324

2425
const createRule = ESLintUtils.RuleCreator(
2526
() => 'https://github.com/gund/eslint-plugin-deprecation',
@@ -288,7 +289,7 @@ function isCallExpression(
288289
function getJsDocDeprecation(tags: ts.JSDocTagInfo[]) {
289290
for (const tag of tags) {
290291
if (tag.name === 'deprecated') {
291-
return { reason: tag.text || '' };
292+
return { reason: stringifyJSDocTagInfoText(tag) };
292293
}
293294
}
294295
return undefined;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as ts from 'typescript';
2+
3+
/**
4+
* Stringifies the text within a JSDocTagInfo AST node with compatibility for
5+
* pre/post TypeScript 4.3 API changes.
6+
*/
7+
export function stringifyJSDocTagInfoText(tag: ts.JSDocTagInfo): string {
8+
return isJSDocTagInfo4Point2AndBefore(tag)
9+
? tag.text ?? ''
10+
: ts.displayPartsToString(tag.text);
11+
}
12+
13+
/**
14+
* Copied from TypeScript 4.2.
15+
* https://github.com/microsoft/TypeScript/blob/fb6c8392681f50a305236a7d662123a69827061f/lib/protocol.d.ts#L2820-L2823
16+
*
17+
* The `text` field was changed from `string` to `SymbolDisplayPart[]` in 4.3.
18+
*/
19+
interface JSDocTagInfo4Point2AndBefore {
20+
name: string;
21+
text?: string;
22+
}
23+
24+
function isJSDocTagInfo4Point2AndBefore(
25+
tag: ts.JSDocTagInfo | JSDocTagInfo4Point2AndBefore,
26+
): tag is JSDocTagInfo4Point2AndBefore {
27+
return typeof tag.text === 'string';
28+
}

0 commit comments

Comments
 (0)