deno_lint
deno_lint copied to clipboard
feat: add ban-untagged-deprecation rule
Fixes: https://github.com/denoland/deno_lint/issues/1266
Considerations
1. Warning Range
Using the Comment#range method would apply warnings to the entire block comment, which isn’t ideal. So instead, the implementation now focuses on issuing warnings only for the specific target range.
For example, in the following file (example.ts):
/**
* @param foo - The input value.
* @deprecated
* @returns The computed result.
*/
export function oldFunction(foo: number): number {
return foo + 1;
}
The warning highlights only the @deprecated tag and the trailing whitespace:
$ ./target/debug/examples/dlint run example.ts --rule ban-untagged-deprecation
error[ban-untagged-deprecation]: The @deprecated tag must include descriptive text
--> /Users/taka/Documents/GitHub/deno_lint/example.ts:3:4
|
3 | * @deprecated
| ^^^^^^^^^^^^^^
= hint: Provide additional context for the @deprecated tag, e.g., '@deprecated since v2.0'
docs: https://lint.deno.land/rules/ban-untagged-deprecation
Found 1 problem
One concern is that while the starting position of the warning is checked in tests using assert_lint_err, the ending position isn’t explicitly covered. If you have ideas on improving this test coverage, or think this behavior could be better, I’d love to hear your thoughts!
2. Valid JSDoc (TSDoc) Tags
Since the spec doesn’t seem to clearly define the syntax, I tried testing what the TSDoc Playground recognizes as valid tags. At least, the current behavior matches the following cases. If you think there’s room for improvement here, I’d love to hear your feedback!
Recognized as Valid Tags:
/** @deprecated */
/**@deprecated */
/*** @deprecated */
/**
* @deprecated
*/
/**
*@deprecated
*/
/**
** @deprecated
*/
/**
@deprecated
*/
/**
This function is @deprecated since v2.0.
*/
Not Recognized as Valid Tags:
/***@deprecated */
/**
**@deprecated
*/
3. Behavior with Multiple @deprecated Tags
When multiple @deprecated tags are present, it seems that TSDoc only recognizes the last one as valid. However, designing the linter to appropriately check only the last tag would have made the logic unnecessarily complex, so the linter is implemented to check all @deprecated tags instead.