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

no-empty-file: Fix false positive with triple-slash directives #1605

Conversation

manovotny
Copy link
Contributor

The simplest fix seems to be to ignore .d.ts files as @babel/eslint-parser and @typescript-eslint/parser still view triple-slash directives as regular comments that produce an empty body.

Fixes #1598

@fisker
Copy link
Collaborator

fisker commented Nov 12, 2021

I think it's possible to get all comments and test that it's start with a /.

@manovotny
Copy link
Contributor Author

@fisker I am trying the "starts with /" route, but shebangs are giving me trouble as they meet that criteria too. I'll keep fiddling.

@fisker
Copy link
Collaborator

fisker commented Nov 12, 2021

I 'm not familiar with this syntax, but I see this line https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/rules/triple-slash-reference.ts#L96

Maybe we can ignore file, if

  1. Starts with / and not one first line, shebang has to be on first line.
  2. Starts with /\s*<reference\s*, we can add missing cases later.

@fisker
Copy link
Collaborator

fisker commented Nov 12, 2021

Wait, I don't think .d.ts can use shebang, so filename check push first char should enough ?

@manovotny
Copy link
Contributor Author

@fisker yeah, never mind. I was making it more difficult than it needed to be. PR has been updated.

rules/no-empty-file.js Outdated Show resolved Hide resolved
rules/no-empty-file.js Outdated Show resolved Hide resolved
rules/no-empty-file.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@fisker fisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Thank you!

@manovotny
Copy link
Contributor Author

@fisker you're welcome!

@sindresorhus sindresorhus changed the title Fixes no-empty-file false positive with triple-slash directives. no-empty-file: Fix false positive with triple-slash directives Nov 15, 2021
@sindresorhus sindresorhus merged commit 6354bb8 into sindresorhus:main Nov 15, 2021
@manovotny manovotny deleted the fix-no-empty-file-false-positive-triple-slash-directives branch November 24, 2021 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positives with no-empty-files
3 participants