From 122ccc1ff85ee5ddcb8e33d847cb32638c6acc64 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Tue, 3 Oct 2023 22:39:53 +0200 Subject: [PATCH] Re-format markdown --- README.md | 50 +++++++++++++++++++++++++++------------- docs/writing-a-plugin.md | 22 ++++++++++-------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 74134a674..d1c1899a3 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,9 @@ For updates or questions, come hang out in [The Knip Barn (Discord)][10], or fol ### Installation - npm install -D knip +``` +npm install -D knip +``` Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.6. @@ -445,7 +447,9 @@ In a more fine-grained manner, you can also ignore only specific issue types: When a repository is self-contained or private, you may want to include entry files when reporting unused exports: - knip --include-entry-exports +``` +knip --include-entry-exports +``` Knip will also report unused exports in entry source files and scripts (such as those referenced in `package.json`). But not in entry and configuration files from plugins, such as `next.config.js` or `src/routes/+page.svelte`. @@ -587,12 +591,16 @@ Alternatively, they can be added to the configuration (e.g. `"exclude": ["depend Use `--include` to report only specific issue types (the following example commands do the same): - knip --include files --include dependencies - knip --include files,dependencies +``` +knip --include files --include dependencies +knip --include files,dependencies +``` Use `--exclude` to ignore reports you're not interested in: - knip --include files --exclude classMembers,enumMembers +``` +knip --include files --exclude classMembers,enumMembers +``` Use `--dependencies` or `--exports` as shortcuts to combine groups of related types. @@ -660,7 +668,8 @@ Knip takes the following JSDoc/TSDoc tags into account: ## Command Line Options - $ npx knip --help +``` +$ npx knip --help ✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects Usage: knip [options] @@ -704,6 +713,7 @@ Knip takes the following JSDoc/TSDoc tags into account: $ knip --debug --debug-file-filter '(specific|particular)-module' More documentation and bug reports: https://github.com/webpro/knip +``` ## Potential boost with `--no-gitignore` @@ -739,15 +749,19 @@ Below some similar commands to get another idea of what Knip does in comparison: The following commands are similar: - depcheck - knip --dependencies +``` +depcheck +knip --dependencies +``` ### unimported The following commands are similar: - unimported - knip --production --dependencies --include files +``` +unimported +knip --production --dependencies --include files +``` Also see [production mode][25]. @@ -755,17 +769,21 @@ Also see [production mode][25]. The following commands are similar: - ts-unused-exports - knip --include exports,types,nsExports,nsTypes - knip --exports # Adds unused enum and class members +``` +ts-unused-exports +knip --include exports,types,nsExports,nsTypes +knip --exports # Adds unused enum and class members +``` ### ts-prune The following commands are similar: - ts-prune - knip --include exports,types - knip --exports # Adds unused exports/types in namespaces and unused enum/class members +``` +ts-prune +knip --include exports,types +knip --exports # Adds unused exports/types in namespaces and unused enum/class members +``` ## Projects using Knip diff --git a/docs/writing-a-plugin.md b/docs/writing-a-plugin.md index 56651f06d..4bddbd0b8 100644 --- a/docs/writing-a-plugin.md +++ b/docs/writing-a-plugin.md @@ -108,15 +108,17 @@ automatically added to [`ENTRY_FILE_PATTERNS`][12]. The `findDependencies` function should do three things: -1. Load and execute the provided configuration file. -2. Find dependencies referenced in this configuration. -3. Return an array of the dependencies. +1. Load and execute the provided configuration file. +2. Find dependencies referenced in this configuration. +3. Return an array of the dependencies. For example, you are using Cool Linter in your project, and running Knip results in some false positives: - Unused dependencies (2) - @cool-linter/awesome-addon - @cool-linter/priority-plugin +``` +Unused dependencies (2) +@cool-linter/awesome-addon +@cool-linter/priority-plugin +``` This is incorrect, since you have `cool-linter.config.json` that references those dependencies! @@ -204,10 +206,10 @@ Cool Linter does not require such files, so we can remove them from our plugin. Let's update the tests to verify our plugin implementation is working correctly. -1. Let's save the example `cool-linter.config.json` in the fixtures directory. Create the file in your IDE, and save it - at `fixtures/plugins/cool-linter/cool-linter.config.json`. +1. Let's save the example `cool-linter.config.json` in the fixtures directory. Create the file in your IDE, and save it + at `fixtures/plugins/cool-linter/cool-linter.config.json`. -2. Update the test at `tests/plugins/cool-linter.test.ts`: +2. Update the test at `tests/plugins/cool-linter.test.ts`: ```ts test('Find dependencies in cool-linter configuration (json)', async () => { @@ -219,7 +221,7 @@ test('Find dependencies in cool-linter configuration (json)', async () => { This verifies the dependencies in `cool-linter.config.json` are correctly returned to the Knip program. -3. Run the test: +3. Run the test: ```sh npx tsx tests/plugins/cool-linter.test.ts