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

chore: update knip config #40

Merged
merged 10 commits into from
Feb 17, 2023

Conversation

RebeccaStevens
Copy link
Collaborator

@RebeccaStevens RebeccaStevens commented Feb 9, 2023

PR Checklist

Overview

When not in production mode, entry files should include test files.
When in production mode, project files should not include test files.

@RebeccaStevens
Copy link
Collaborator Author

Using this config, knip pass in #33 with flag --production. It still fails when not running in production mode.

@RebeccaStevens RebeccaStevens changed the title chore: use a more complete list of entry and project files chore: update knip config Feb 9, 2023
knip.jsonc Outdated Show resolved Hide resolved
@JoshuaKGoldberg
Copy link
Owner

Marking this as blocked on resolving discussion in webpro-nl/knip#62 - in case it ends up impacting us here.

@JoshuaKGoldberg JoshuaKGoldberg added the status: blocked Waiting for something else to be resolved 🙅 label Feb 12, 2023
@webpro
Copy link
Contributor

webpro commented Feb 12, 2023

Just saying, in the meantime you could add the specific files as entry files to unblock this

@JoshuaKGoldberg JoshuaKGoldberg added status: waiting for author Needs an action taken by the original poster status: blocked Waiting for something else to be resolved 🙅 and removed status: blocked Waiting for something else to be resolved 🙅 labels Feb 12, 2023
@codecov
Copy link

codecov bot commented Feb 13, 2023

Codecov Report

Merging #40 (418eae9) into main (591db49) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main      #40   +/-   ##
=======================================
  Coverage   19.74%   19.74%           
=======================================
  Files          15       15           
  Lines         395      395           
  Branches      161      161           
=======================================
  Hits           78       78           
  Misses        299      299           
  Partials       18       18           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@RebeccaStevens
Copy link
Collaborator Author

RebeccaStevens commented Feb 13, 2023

in the meantime you could add the specific files as entry files

Just made this change.

I also made it so that knip is called in the ci both with and without --production.

knip.jsonc Outdated Show resolved Hide resolved
Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Requesting changes only in that I'd like to see how to make lint:knip:production fail, the code LGTM!

@JoshuaKGoldberg JoshuaKGoldberg removed the status: blocked Waiting for something else to be resolved 🙅 label Feb 13, 2023
@RebeccaStevens
Copy link
Collaborator Author

RebeccaStevens commented Feb 14, 2023

I'd like to see how to make lint:knip:production fail

If you make a new file (src/foo.ts) and put an export in it (export const foo = 1), both the version of knip will report this unused exported. If you then create a test file for that file (stc/foo.test.ts) and import the export (import { foo } from "./foo"), now only the production version of knip will fail.

At least that's how it should work. I did some testing though and it seems like something with the glob patterns isn't work as expected. I'll look into this. - Push a fix for this. Issue was cause by unexpected default glob pattern being added to our defined ones.

"$schema": "https://unpkg.com/knip@next/schema.json",
"entry": ["src/**/index.ts!"],
"project": ["src/**/*.ts!", "!src/test/**/*.ts!", "!src/**/*.test.ts!"]
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@webpro It doesn't seem to currently be possible to use a single config file for our use case.

Essentially, we want this config, but with the comment addressed.

{
	"$schema": "https://unpkg.com/knip@next/schema.json",
	"entry": ["src/**/index.ts!", "src/**/*.test.ts"],
	"project": [
		"src/**/*.ts!",
		"!src/test/**/*.ts!", // <-- We want these "not" globs to only apply in production mode.
		"!src/**/*.test.ts!"  // <-- Using a separate production specific config seems to be the only way to currently achieve this.
	]
}

When using config that runs logic (e.g. knip.ts), it would be great if we could access a isProduction variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the late reply, but somehow today this popped up in the back of my mind. Any chance you could give it a shot with the latest Knip v1? I think you don't need any configuration anymore for either dev or production mode :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah scratch that, it's almost true, you would still need to add **/index.ts as entry files (as that is fixed only in v2).

Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

💯 thanks!

Whenever you're happy to merge, let's do it!

package.json Outdated Show resolved Hide resolved
@RebeccaStevens RebeccaStevens enabled auto-merge (squash) February 17, 2023 12:04
@RebeccaStevens RebeccaStevens merged commit acd3836 into JoshuaKGoldberg:main Feb 17, 2023
@RebeccaStevens RebeccaStevens removed the status: waiting for author Needs an action taken by the original poster label Feb 20, 2023
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.

3 participants