Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ban-untagged-deprecation rule #1373

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

takaebato
Copy link

@takaebato takaebato commented Dec 7, 2024

Fixes: #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.

@CLAassistant
Copy link

CLAassistant commented Dec 7, 2024

CLA assistant check
All committers have signed the CLA.

@takaebato takaebato force-pushed the add-ban-untagged-deprecation-rule branch from cc08711 to fc996c3 Compare December 7, 2024 10:44
@takaebato takaebato force-pushed the add-ban-untagged-deprecation-rule branch from fc996c3 to ad86429 Compare December 7, 2024 10:47
@takaebato takaebato force-pushed the add-ban-untagged-deprecation-rule branch from ad86429 to 289d947 Compare December 7, 2024 11:00
@takaebato takaebato changed the title Add ban-untagged-deprecation rule feat: add ban-untagged-deprecation rule Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

suggestion: ban-untagged-deprecation
2 participants