Skip to content

[code-infra] Add lint rule requiring explanation on ts-expect-error #1524

Closed

Description

@brijeshb42

Summary

We should add a lint rule that makes an explanation mandatory on each // @ts-expect-error.

Motivation

A bare // @ts-expect-error suppresses a type error without recording why. Over time these become hard to audit: nobody knows whether the suppression is still needed, what it was working around, or whether removing it is safe. Requiring an explanation forces the author to document the reason and makes future cleanup tractable.

Proposal

Enable the @typescript-eslint/ban-ts-comment rule with a minimum description length for ts-expect-error (and ideally ts-ignore), e.g.:

'@typescript-eslint/ban-ts-comment': ['error', {
  'ts-expect-error': 'allow-with-description',
  minimumDescriptionLength: 10,
}]

This rejects:

// @ts-expect-error
foo.bar();

and requires:

// @ts-expect-error - bar is injected at runtime by the plugin
foo.bar();

Notes

  • Existing bare suppressions will need explanations added (can be done incrementally or in one pass).

Activity

  1. added
    status: waiting for maintainer
    on Jun 9, 2026
  2. brijeshb42 commented on Jun 9, 2026

    @brijeshb42
    ContributorAuthor

    Context / prior discussion: mui/material-ui#48616 (review)

  3. changed the title [-]Add lint rule requiring an explanation on every `// @ts-expect-error`[/-] [+][code-infra] Add lint rule requiring explanation on ts-expect-error[/+] on Jun 9, 2026
  4. Janpot commented on Jun 9, 2026

    @Janpot
    Member

    Suggestion: If we're not already, we could also reject // @ts-ignore in favor for // @ts-expect-error. Because // @ts-ignore doesn't break if the warning is fixed. We should only use it in very specific cases (e.g. to suppress a warning that only happens in one of two different typescript versions we test)

  5. added
    scope: code-infra
    on Jun 9, 2026
  6. added
    type: enhancement
    on Jun 10, 2026
  7. removed
    status: waiting for maintainer
    on Jun 12, 2026
  8. github-actions commented on Oct 8, 2026

    @github-actions

    This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
    Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: code-infratype: enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions