Skip to content

Commit 403d257

Browse files
committedNov 12, 2024·
Respect and document NO_COLOR
1 parent 2ad6583 commit 403d257

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed
 

Diff for: ‎packages/docs/src/content/docs/reference/cli.md

+39-29
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ This is equal to `bunx --bun knip`
4040
Requires [Bun][1] to be installed. Also see [known issues][2] for the type of
4141
issues this might help with.
4242

43+
### NO_COLOR
44+
45+
The default reporters use the [NO_COLOR][3] friendly [picocolors][4]:
46+
47+
```sh
48+
NO_COLOR=1 knip
49+
```
50+
4351
## Troubleshooting
4452

4553
### `--debug`
@@ -75,21 +83,21 @@ Total running time: 5s (mem: 631.27MB)
7583
- `sum` the accumulated time of all invocations
7684

7785
This is not yet available in Bun, since it does not support
78-
`performance.timerify` ([GitHub issue][3]).
86+
`performance.timerify` ([GitHub issue][5]).
7987

8088
### `--trace`
8189

8290
Trace exports to see where they are imported.
8391

84-
Also see [Trace][4].
92+
Also see [Trace][6].
8593

8694
### `--trace-export [name]`
8795

88-
Trace export name to see where it's imported. Implies [--trace][5].
96+
Trace export name to see where it's imported. Implies [--trace][7].
8997

9098
### `--trace-file [path]`
9199

92-
Trace file to see where its exports are imported. Implies [--trace][5].
100+
Trace file to see where its exports are imported. Implies [--trace][7].
93101

94102
## Configuration
95103

@@ -115,7 +123,7 @@ Default location: `tsconfig.json`
115123

116124
### `--workspace [dir]`
117125

118-
[Lint a single workspace][6] including its ancestor and dependent workspaces.
126+
[Lint a single workspace][8] including its ancestor and dependent workspaces.
119127
The default behavior is to lint all configured workspaces.
120128

121129
Shortcut: `-W`
@@ -139,7 +147,7 @@ files when reporting unused exports:
139147
knip --include-entry-exports
140148
```
141149

142-
Also see [includeEntryExports][7].
150+
Also see [includeEntryExports][9].
143151

144152
### `--include-libs`
145153

@@ -150,11 +158,11 @@ Getting false positives for exports consumed by external libraries? Try the
150158
knip --include-libs
151159
```
152160

153-
Also see [external libs][8].
161+
Also see [external libs][10].
154162

155163
### `--isolate-workspaces`
156164

157-
By default, Knip optimizes performance using [workspace sharing][9] to existing
165+
By default, Knip optimizes performance using [workspace sharing][11] to existing
158166
TypeScript programs, based on the compatibility of their `compilerOptions`. This
159167
flag disables this behavior and creates one program per workspace, which is
160168
slower but memory is spread more evenly over time.
@@ -171,18 +179,18 @@ Lint only production source files. This excludes:
171179
- Storybook stories
172180
- `devDependencies` from `package.json`
173181

174-
Read more at [Production Mode][10].
182+
Read more at [Production Mode][12].
175183

176184
### `--strict`
177185

178186
Isolate workspaces and consider only direct dependencies. Implies [production
179-
mode][11].
187+
mode][13].
180188

181-
Read more at [Production Mode][10].
189+
Read more at [Production Mode][12].
182190

183191
### `--fix`
184192

185-
Read more at [auto-fix][12].
193+
Read more at [auto-fix][14].
186194

187195
### `--cache`
188196

@@ -208,7 +216,7 @@ changes in `package.json` and/or `node_modules` are not supported.
208216

209217
## Filters
210218

211-
Available [issue types][13] when filtering output using `--include` or
219+
Available [issue types][15] when filtering output using `--include` or
212220
`--exclude`:
213221

214222
- `files`
@@ -264,7 +272,7 @@ Shortcut to include all types of export issues:
264272

265273
### `--experimental-tags`
266274

267-
Deprecated. Use [--tags][14] instead.
275+
Deprecated. Use [--tags][16] instead.
268276

269277
### `--tags`
270278

@@ -318,7 +326,7 @@ Can be repeated. Example:
318326
knip --reporter compact
319327
```
320328

321-
Also see [Reporters & Preprocessors][15].
329+
Also see [Reporters & Preprocessors][17].
322330

323331
### `--reporter-options [json]`
324332

@@ -353,7 +361,7 @@ Pass extra options to the preprocessor as JSON string.
353361
knip --preprocessor ./preproc.ts --preprocessor-options '{"key":"value"}'
354362
```
355363

356-
Also see [Reporters & Preprocessors][15].
364+
Also see [Reporters & Preprocessors][17].
357365

358366
## Exit code
359367

@@ -375,16 +383,18 @@ Maximum number of issues before non-zero exit code. Default: `0`
375383

376384
[1]: https://bun.sh
377385
[2]: ../reference/known-issues.md
378-
[3]: https://github.com/oven-sh/bun/issues/9271
379-
[4]: ../guides/troubleshooting.md#trace
380-
[5]: #--trace
381-
[6]: ../features/monorepos-and-workspaces.md#lint-a-single-workspace
382-
[7]: ./configuration.md#includeentryexports
383-
[8]: ../guides/handling-issues.mdx#external-libraries
384-
[9]: ../guides/performance.md#workspace-sharing
385-
[10]: ../features/production-mode.md
386-
[11]: #--production
387-
[12]: ../features/auto-fix.mdx
388-
[13]: ./issue-types.md
389-
[14]: #--tags
390-
[15]: ../features/reporters.md
386+
[3]: https://no-color.org/
387+
[4]: https://www.npmjs.com/package/picocolors
388+
[5]: https://github.com/oven-sh/bun/issues/9271
389+
[6]: ../guides/troubleshooting.md#trace
390+
[7]: #--trace
391+
[8]: ../features/monorepos-and-workspaces.md#lint-a-single-workspace
392+
[9]: ./configuration.md#includeentryexports
393+
[10]: ../guides/handling-issues.mdx#external-libraries
394+
[11]: ../guides/performance.md#workspace-sharing
395+
[12]: ../features/production-mode.md
396+
[13]: #--production
397+
[14]: ../features/auto-fix.mdx
398+
[15]: ./issue-types.md
399+
[16]: #--tags
400+
[17]: ../features/reporters.md

Diff for: ‎packages/knip/src/util/debug.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const { debug } = parsedArgValues;
66

77
const IS_DEBUG_ENABLED = debug ?? false;
88

9+
const IS_COLORS = !process.env.NO_COLOR;
10+
911
const noop = () => {};
1012

11-
const inspectOptions = { maxArrayLength: null, depth: null, colors: true };
13+
const inspectOptions = { maxArrayLength: null, depth: null, colors: IS_COLORS };
1214

1315
/** @public */
1416
export const inspect = (obj: unknown) => console.log(util.inspect(obj, inspectOptions));

0 commit comments

Comments
 (0)
Please sign in to comment.