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

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

Open
4 tasks done
auvred opened this issue Mar 22, 2024 · 2 comments
Open
4 tasks done
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@auvred
Copy link
Member

auvred commented Mar 22, 2024

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

@auvred auvred added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 22, 2024
@bradzacher
Copy link
Member

I'm not sure I agree - what's the problem with reporting it anywhere?
The user intent was clear even if it didn't work.

Is there a usecase for keeping these comments?

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Mar 22, 2024
@auvred
Copy link
Member Author

auvred commented Mar 23, 2024

Is there a usecase for keeping these comments?

I don't think so :)

My intention was to be completely consistent with TypeScript's handling of directive comments.

Since after #8416, the following cases are no longer reported:

/* @ts-nocheck */
/** @ts-nocheck */
///// @ts-nocheck

So I thought it would be nice to fix the last inconsistency with TS behavior - reporting on misplaced @ts-nocheck comments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants