Skip to content

Bug: [ban-ts-comment] false positive when @ts-nocheck is not at the beginning of the file #8753

Closed
@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.4.2&fileType=.ts&code=FBA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AIwEMnb9layAewC2wxC3RRE0aIOiRwYAL4glQA&tsconfig=&tokens=false

Repro Code

const a = 1

// @ts-nocheck - should not be reported

// TS error is not actually suppressed
const b: string = a

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/ban-ts-comment": "error"
  }
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

// @ts-nocheck should not be reported because valid TS pragmas should be placed at the beginning of the file

Actual Result

// @ts-nocheck and // @ts-check are reported even if they are not valid TS pragmas

Additional Info

Follow up for #8416

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