Skip to content

Bug: [ban-ts-comment] incorrectly handles directives in multiline block comments #8368

@auvred

Description

@auvred

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.3.3&fileType=.tsx&code=PQKhCgAJoAQFwM4FoCWBzAdgewE4FNIRhoTSzzhiAeJSBACywFcAbAE0nwAdc4AuSAHkA0uADGWDAjiQAZliwBGAdJwoMaSAF5Ii8OFAhoCLAFsCcPAA8Z9PPiixEqTLgJFynz5Ug06jVg5uXgEAIQBVAHFxSWk5BQAmFTg1DW1dfVBIeGRsMTsxAGtCYi8yyB8-BmZ2SGwZYJx%2BSAjoiSkZeSwAZmTUzR09AyMcpHy8IpLy6craasC6rAa8HiawqJiO%2BKwAFj71Ad0gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AIwEMnb9layAewC2wxC3RgA2uGw5E0aIOiQANLLlY52SHwEALRGQDWk-HETrtOvYgAepMnQVKVGAGad4ySxu27%2BSgBzJmVEMwsrayg9ULJDEwjYRD8IAF8-AF1ZDLSgA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

/**
   @ts-ignore */                    // <- should report: OK
const foo1: string = 1

/**  some text here
   @ts-ignore */                    // <- should report: BUG
const foo2: string = 1



/* @ts-nocheck */                   // <- should not report: BUG
const foo3: string = 1

/* @ts-check */                     // <- should not report: BUG
const foo4: string = 1

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/ban-ts-comment": [
      "error",
      {
        "ts-check": true,
        "ts-expect-error": false,
        "ts-ignore": true,
        "ts-nocheck": true
      }
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

There are two issues:

  1. It should report on multiline block comments with any extra characters on lines before @ts-ignore or @ts-expect-error directives (as TypeScript tries to find these directives in the last line of block comment (src/compiler/scanner.ts)

  2. It shouldn't report on @ts-nocheck and @ts-check directives used in block comments. As they are only valid as single-line comment pragmas - src/compiler/types.ts

Actual Result

  1. It doesn't report on
/**  some text here
   @ts-ignore */
  1. It does report on
/* @ts-nocheck */
/* @ts-check */

Additional Info

I decided to report on both problems in one issue, as they are very close to each other and it would be much easier to fix them both in one PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions