-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): stop warning on @ts-nocheck comments which aren't at the beginning of the file #10046
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
fix(eslint-plugin): stop warning on @ts-nocheck comments which aren't at the beginning of the file #10046
Conversation
…not at the beginning of the file
Thanks for the PR, @ronami! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d07c3ee. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10046 +/- ##
==========================================
- Coverage 88.73% 86.02% -2.72%
==========================================
Files 426 427 +1
Lines 14881 14896 +15
Branches 4327 4331 +4
==========================================
- Hits 13205 12814 -391
- Misses 1534 1736 +202
- Partials 142 346 +204
Flags with carried forward coverage won't be shown. Click here to find out more.
|
if ( | ||
directive === 'nocheck' && | ||
firstStatement && | ||
isPositionEarlierThan(firstStatement.loc.start, comment.loc.start) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isPositionEarlierThan(firstStatement.loc.start, comment.loc.start) | |
firstStatement.loc.start.line <= comment.loc.start.line |
[Bug] If // @ts-nocheck
comment is placed on the line before actual code, but its loc.start.column
is greater than firstStatement.loc.start.column
, the nocheck
directive is not reported, even though this is a valid TS pragma and it effectively suppresses all TS errors.
/// @ts-nocheck
const a: true = false
I don't think we need to compare loc
columns here. Since singleline comments should be placed either on their own line or at the end of a line.
And if // @ts-nocheck
is placed at the end of a line, it's no longer a valid TS pragma.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops. 🙈
Yeah, I understand that checking columns alone is a bug, my intention was not to report the following:
/* @ts-nocheck - should not be reported */ const a = 1;
The function I was going to write was something like this (I also missed adding a test for such a case or checking it actually fails at all):
function isPositionEarlierThan(
a: TSESTree.Position,
b: TSESTree.Position,
): boolean {
if (a.line > b.line) {
return false;
}
return a.line === b.line && a.column < b.column;
}
But I can see block comments with ts-nocheck
don't disable type-checking and the lint rule covers this already.
I've changed my code accordingly, thanks 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth including my example in the test suite as well. That way we can prevent regressions in the future.
@@ -1127,6 +1119,22 @@ if (false) { | |||
}, | |||
], | |||
}, | |||
{ | |||
// comment's column > first statement's column | |||
// eslint-disable-next-line @typescript-eslint/internal/plugin-test-formatting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used an eslint-disable
comment over noFormat()
since it doesn't handle disabling indentation checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
2d6ee87
into
typescript-eslint:main
PR Checklist
Overview
This PR resolves #8753 and stops warning on
// @ts-nocheck
comments which are not at the beginning of the file: