Skip to content

Commit

Permalink
chore: introduce knip (#174)
Browse files Browse the repository at this point in the history
* chore: add knip + config

* chore: simplify glob pattern for eslint markdown override

* chore: remove ts-prune & replace workflow

* chore: add dependencies to ignore (until Knip has related plugins)

* chore: remove unused yargs package

* chore: add markdownlint to ignored dependencies

* chore: enable production mode in knip's config

* Sorting, and removed yargs

* Add knip to cspell.json

* chore: remove dependencies now having plugins in Knip config

* docs: replace ts-prune with knip

* Fix lint

* Updated docs and setup script

* Bump knip and ignore eslint-plugin-markdown

* Simplify output knip.jsonc

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
  • Loading branch information
webpro and JoshuaKGoldberg committed Jan 20, 2023
1 parent 80e0a78 commit c652bda
Show file tree
Hide file tree
Showing 10 changed files with 857 additions and 276 deletions.
6 changes: 3 additions & 3 deletions .github/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ It should be applied automatically when you save files in VS Code or make a Git
This package includes several forms of linting to enforce consistent code quality and styling.
Each should be shown in VS Code, and can be run manually on the command-line:

- `pnpm lint` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files
- `pnpm lint:knip` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports
- `pnpm lint:md` ([Markdownlint](https://github.com/DavidAnson/markdownlint)): Checks Markdown source files
- `pnpm lint:package` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the `package.json` file
- `pnpm lint:packages` ([pnpm-deduplicate](https://github.com/ocavue/pnpm-deduplicate)): Deduplicates packages in the `pnpm-lock.yml` file
- `pnpm lint:prune` ([ts-prune](https://github.com/nadeesha/ts-prune)): Detects unused exports in TypeScript source files
- `pnpm lint:spelling` ([cspell](https://cspell.org)): Spell checks across all source files
- `pnpm lint` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files

## Testing

Expand All @@ -47,7 +47,7 @@ You can run it locally on the command-line:
pnpm run test
```

Add the `--coverage` flat to compute test coverage and place reports in the `coverage/` directory:
Add the `--coverage` flag to compute test coverage and place reports in the `coverage/` directory:

```shell
pnpm run test --coverage
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/prune.yml → .github/workflows/knip.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint Prune
name: Lint Knip

on:
push:
Expand All @@ -7,9 +7,9 @@ on:
pull_request:

jobs:
prune:
knip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/prepare
- run: pnpm lint:prune
- run: pnpm lint:knip
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ jobs:
checks: [
{ context: "build" },
{ context: "compliance" },
{ context: "knip" },
{ context: "lint" },
{ context: "markdown" },
{ context: "package" },
{ context: "packages" },
{ context: "prettier" },
{ context: "prune" },
{ context: "spelling" },
{ context: "test" },
],
Expand Down
4 changes: 0 additions & 4 deletions .ts-prunerc

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ It sets up the following tooling for you:

- [**All Contributors**](https://allcontributors.org): Tracks various kinds of contributions and displays them in a nicely formatted table in the README.md.
- [**ESLint**](https://eslint.org): Static analysis for JavaScript code, configured with [typescript-eslint](https://typescript-eslint.io) for TypeScript code and other general-use plugins.
- [**Knip**](https://github.com/webpro/knip): Detects unused files, dependencies, and code exports.
- [**Markdownlint**](https://github.com/DavidAnson/markdownlint): Static analysis for Markdown code.
- [**pnpm**](https://pnpm.io): Disk-efficient package manager alternative.
- [**PR Compliance Action**](https://github.com/mtfoley/pr-compliance-action): Checks PRs for compliance on chore such as addressing a linked issue and proper title formatting.
- [**Prettier**](https://prettier.io): Opinionated formatting for code, run on file save and as a Git commit hook via [husky](https://typicode.github.io/husky) and [lint-staged](https://github.com/okonet/lint-staged).
- [**release-it**](https://github.com/release-it/release-it): Generates changelogs, bumps the package version, and publishes to GitHub and npm based on [conventional commits](https://www.conventionalcommits.org).
- [**Renovate**](https://docs.renovatebot.com): Keeps dependencies up-to-date with PRs, configured to wait a few days after each update for safety.
- [**ts-prune**](https://github.com/nadeesha/ts-prune): Unused exports detection for TypeScript code.
- [**TypeScript**](https://typescriptlang.org): A typed superset of JavaScript, configured with strict compiler options.
- [**Vitest**](https://vitest.dev): Fast unit tests, configured with coverage tracking.

Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"contributorsrc",
"conventionalcommits",
"infile",
"knip",
"lcov",
"quickstart",
"wontfix"
Expand Down
12 changes: 12 additions & 0 deletions knip.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://unpkg.com/knip@next/schema.json",
"entry": ["src/index.ts!", "script/setup*.js"],
"project": ["src/**/*.ts!", "script/**/*.js"],

"ignoreDependencies": [
// Remove when Knip understands ESLint overrides > extends:
"eslint-plugin-markdown",
// Remove when Knip extends the release-it plugin to pluck binaries from hooks:
"should-semantic-release"
]
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@typescript-eslint/parser": "^5.48.2",
"@vitest/coverage-istanbul": "^0.27.2",
"chalk": "^5.2.0",
"cspell": "^6.19.0",
"cspell": "^6.19.1",
"enquirer": "^2.3.6",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
Expand All @@ -21,6 +21,7 @@
"eslint-plugin-vitest": "^0.0.29",
"husky": "^8.0.3",
"jsonc-eslint-parser": "^2.1.0",
"knip": "1.9.0",
"lint-staged": "^13.1.0",
"markdownlint": "^0.27.0",
"markdownlint-cli": "^0.33.0",
Expand All @@ -33,10 +34,8 @@
"replace-in-file": "^6.3.5",
"sentences-per-line": "^0.2.1",
"should-semantic-release": "^0.0.1",
"ts-prune": "^0.10.3",
"typescript": "^4.9.4",
"vitest": "^0.27.2",
"yargs": "^17.6.2"
"vitest": "^0.27.2"
},
"engines": {
"node": ">=18"
Expand All @@ -57,10 +56,10 @@
"format": "prettier \"**/*\" --ignore-unknown",
"format:write": "pnpm format --write",
"lint": "eslint . --max-warnings 0 --report-unused-disable-directives",
"lint:knip": "knip",
"lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line",
"lint:package": "npmPkgJsonLint .",
"lint:packages": "pnpm-deduplicate --list",
"lint:prune": "ts-prune",
"lint:spelling": "cspell \"**\" \".github/**/*\"",
"prepare": "husky install",
"setup": "npx --yes zx --quiet script/setup.js",
Expand Down

0 comments on commit c652bda

Please sign in to comment.