Skip to content

Commit 4e42ff8

Browse files
committedNov 28, 2023
Throw for invalid issue types when using include/exclude filter (closes #366)
1 parent 6407d4d commit 4e42ff8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed
 

‎packages/docs/src/content/docs/reference/issue-types.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ Knip reports the following types of issues:
2525
- NSs = namespaces
2626
- When an issue type has zero issues, it is not shown.
2727

28-
Note that `devDependencies` is covered with a single key for all `dependencies`.
29-
In [strict production mode][1], `devDependencies` are not included.
28+
The `devDependencies` are covered in a single key for all `dependencies`. In
29+
[strict production mode][1], `devDependencies` are not included.
30+
31+
The `types` issue type includes `enum`, `interface` and `type` exports.
3032

3133
[1]: ../features/production-mode.md#strict-mode

‎packages/knip/src/util/cli-arguments.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Options:
1414
--no-gitignore Don't use .gitignore
1515
--include Report only provided issue type(s), can be comma-separated or repeated (1)
1616
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
17-
--dependencies Shortcut for --include dependencies,unlisted,unresolved
17+
--dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved
1818
--exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
1919
--include-entry-exports Include entry files when reporting unused exports
2020
--isolate-workspaces Isolated workspaces in monorepo

‎packages/knip/src/util/get-included-issue-types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ISSUE_TYPES } from '../constants.js';
2+
import { ConfigurationError } from './errors.js';
23
import type { Report } from '../types/issues.js';
34

45
type CLIArguments = {
@@ -20,6 +21,11 @@ export const getIncludedIssueTypes = (
2021
cliArgs: CLIArguments,
2122
{ include = [], exclude = [], isProduction = false }: Options = {}
2223
) => {
24+
[...cliArgs.include, ...cliArgs.exclude, ...include, ...exclude].forEach(type => {
25+
// @ts-expect-error The point is that we're checking for invalid issue types
26+
if (!ISSUE_TYPES.includes(type)) throw new ConfigurationError(`Invalid issue type: ${type}`);
27+
});
28+
2329
if (cliArgs.dependencies) {
2430
cliArgs.include = [
2531
...cliArgs.include,

0 commit comments

Comments
 (0)
Please sign in to comment.