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
15 changes: 15 additions & 0 deletions .github/workflows/knip-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint Knip (Production)

on:
push:
branches:
- main
pull_request:

jobs:
knip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/prepare
- run: pnpm lint:knip:production
2 changes: 1 addition & 1 deletion .github/workflows/knip.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint Knip
name: Lint Knip (Development)

on:
push:
Expand Down
6 changes: 2 additions & 4 deletions knip.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"$schema": "https://unpkg.com/knip@next/schema.json",
"entry": "src/index.ts!",
"project": "src/**/*.ts!",
// TODO: /~https://github.com/JoshuaKGoldberg/ts-api-utils/issues/45
"ignore": ["src/nodes/typeGuards/!(*.test).ts"]
"entry": ["src/**/index.ts", "src/**/*.test.ts"],
"project": ["src/**/*.ts"]
}
5 changes: 5 additions & 0 deletions knip.production.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$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).

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"format": "prettier \"**/*\" --ignore-unknown",
"format:write": "pnpm format --write",
"lint": "eslint . --max-warnings 0 --report-unused-disable-directives",
"lint:knip": "knip",
"lint:knip": "knip --config knip.jsonc",
"lint:knip:production": "knip -c knip.production.jsonc --production",
RebeccaStevens marked this conversation as resolved.
Show resolved Hide resolved
"lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line",
"lint:package": "npmPkgJsonLint .",
"lint:packages": "pnpm-deduplicate --list",
Expand Down