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

"ignore" file working even though it shouldn't based on the docs #650

Closed
swingthrough opened this issue May 22, 2024 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@swingthrough
Copy link

When I run knip --include files to list unused files in my project, there are a couple of files shown, one of which is src/mockServiceWorker.js.

So I created knip.config.ts with the following configuration:

import type { KnipConfig } from 'knip';

const config: KnipConfig = {
	ignore: ['src/mockServiceWorker.js'],
};

export default config;

If I run knip --include files with this config, it no longer reports src/mockServiceWorker.js.

However, in the docs there is a statement:

This is not a good idea, since ignore patterns have only one goal: to exclude issues in matching files from the report. Files matching ignore patterns are not excluded from the analysis, only their issues are not reported.

Why does it work then?

Also what would be the correct way to exclude it?
I tried this:

import type { KnipConfig } from 'knip';

const config: KnipConfig = {
	project: [
		'**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}',
		'!src/mockServiceWorker.js',
	],
};

export default config;

And it works. Is this the correct way?

@swingthrough swingthrough added the bug Something isn't working label May 22, 2024
@webpro
Copy link
Collaborator

webpro commented May 22, 2024

Both are fine, the latter is recommended.

The docs don't contradict anything here?

@swingthrough
Copy link
Author

When using ignore, based on the statement:

This is not a good idea, since ignore patterns have only one goal: to exclude issues in matching files from the report. Files matching ignore patterns are not excluded from the analysis, only their issues are not reported.

If I just ran knip command:

exclude issues in matching files from the report

I would expect it to report e.g. an unused export inside of mockServiceWorker.js.

Files matching ignore patterns are not excluded from the analysis, only their issues are not reported.

In the list of unused files, I would expect mockServiceWorker.js to still be shown.

@swingthrough
Copy link
Author

Okay I think I get it now, it also states:

This also hurts performance, since the files are first analyzed, and eventually filtered out.

I interpreted the part "only their issues are not reported" as issues inside the file, but I guess it means the whole file being unused is also an issue of the file, and therefore filtered out (but only after the analysis ran on the file).

@webpro
Copy link
Collaborator

webpro commented May 22, 2024

Indeed! Any issue with files that match the ignore pattern is not reported.

@webpro webpro closed this as completed May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants