Skip to content

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

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

Closed
4 tasks done
auvred opened this issue Mar 22, 2024 · 4 comments · Fixed by #10046
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. 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 team members 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 team members 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!

@JoshuaKGoldberg
Copy link
Member

@auvred sorry, I'm a little lost - what should happen here?

@Josh-Cena
Copy link
Member

@JoshuaKGoldberg Comments that look like TS comment directives but actually are just normal comments are being reported. They shouldn't.

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed awaiting response Issues waiting for a reply from the OP or another party labels Jun 4, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Oct 15, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
4 participants