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: Added option to allow comments #2300

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

AekoArray
Copy link

@AekoArray AekoArray commented Mar 25, 2024

Hello, this is my first experience in open source. Could you see the implementation?

Fix #2218

Allow only comments in files

"unicorn/no-empty-file": {
    "allow": [
        "comments"
	]
}

@AekoArray AekoArray changed the title Added option to allow comments no-empty-file: Added option to allow comments Mar 25, 2024
@sindresorhus
Copy link
Owner

Thanks for contributing. There are linting issues that needs to be resolved.

@AekoArray
Copy link
Author

AekoArray commented Mar 27, 2024

Hello! Can you please tell me how to fix linting issues? I tried running the command to update snapshots
npm run test:js -- test/no-empty-file.mjs -u
but it didn't help. Are there any other ways to fix them?
@sindresorhus

@fisker
Copy link
Collaborator

fisker commented Mar 27, 2024

You need Node.js 20 to update snapshots

# Locked due to the difference of `zlib.gzipSync()` between Node.js versions
node-version: 20

@AekoArray
Copy link
Author

AekoArray commented Mar 28, 2024

You need Node.js 20 to update snapshots

# Locked due to the difference of `zlib.gzipSync()` between Node.js versions
node-version: 20

Thank you! This helped solve the linting problem. Could you please help with "Integration Test 3"? Another PR has the same problem with this test.
Also on the main branch I have the same issue with a "Integration Test 3"

@AekoArray
Copy link
Author

@fisker Hello, could you check this PR again please?

@@ -15,9 +15,17 @@ const isTripleSlashDirective = node =>
const hasTripeSlashDirectives = comments =>
comments.some(currentNode => isTripleSlashDirective(currentNode));

const isProgramFileEmpty = node => node.type === 'Program' && node.body.length === 0;

const isAllowOnlyCommentsFile = (option, node) => option.allow.includes('comments') && isProgramFileEmpty(node);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have difficult to understand this, shouldn't it be something like allowComments && hasComment?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel /* comment */ {} won't pass, but it should.

@sindresorhus
Copy link
Owner

@AekoArray Bump

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.

no-empty-file should be configurable
3 participants