feat(cli): honor NO_COLOR#8331
Conversation
Disables chalk colors and prettyjson colors (deploy, sites:create, status, status:hooks, watch) when NO_COLOR is set, per no-color.org.
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis change introduces NO_COLOR environment variable support via a new exported Estimated code review effort: 2 (Simple) | ~12 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 Benchmark resultsComparing with 3c41e72
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/utils/command-helpers.ts (2)
36-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicate NO_COLOR/--json condition — extract shared helper.
The
argv.includes('--json') || shouldDisableColors()expression is duplicated betweenchalkinit (Line 39) andprettyJsonRenderOptions()(Line 43). Extracting a singleshouldUseNoColor()helper would prevent the two call sites from drifting if the condition changes later.♻️ Proposed refactor
+const shouldUseNoColor = (): boolean => argv.includes('--json') || shouldDisableColors() + -export const chalk = safeChalk(argv.includes('--json') || shouldDisableColors()) +export const chalk = safeChalk(shouldUseNoColor()) export const prettyJsonRenderOptions = (): { noColor: boolean } => ({ - noColor: argv.includes('--json') || shouldDisableColors(), + noColor: shouldUseNoColor(), })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/command-helpers.ts` around lines 36 - 44, The NO_COLOR/--json check is duplicated between the `chalk` initialization and `prettyJsonRenderOptions()`, so extract a shared helper in `command-helpers.ts` (for example alongside `shouldDisableColors`) and use it in both places. Keep the existing `shouldDisableColors` behavior intact, but centralize the combined `argv.includes('--json') || shouldDisableColors()` logic so `chalk` and `prettyJsonRenderOptions` stay consistent if the condition changes later.
36-42: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDoc comments describe implementation behavior.
The added comments on Lines 36 and 41 explain what the following line does (e.g., "any non-empty value disables colors"), which the guideline for
.tsfiles says to avoid — code should be self-explanatory instead of comment-annotated. As per path instructions, "Never write comments on what the code does; make the code clean and self-explanatory instead."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/command-helpers.ts` around lines 36 - 42, The new doc comments on shouldDisableColors, chalk, and prettyJsonRenderOptions are describing implementation behavior instead of letting the code speak for itself. Remove those explanatory comments from command-helpers.ts and keep the logic self-explanatory through the existing identifiers shouldDisableColors, chalk, and prettyJsonRenderOptions; if clarification is still needed, prefer clearer naming or structure over comments.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/utils/command-helpers.ts`:
- Around line 36-44: The NO_COLOR/--json check is duplicated between the `chalk`
initialization and `prettyJsonRenderOptions()`, so extract a shared helper in
`command-helpers.ts` (for example alongside `shouldDisableColors`) and use it in
both places. Keep the existing `shouldDisableColors` behavior intact, but
centralize the combined `argv.includes('--json') || shouldDisableColors()` logic
so `chalk` and `prettyJsonRenderOptions` stay consistent if the condition
changes later.
- Around line 36-42: The new doc comments on shouldDisableColors, chalk, and
prettyJsonRenderOptions are describing implementation behavior instead of
letting the code speak for itself. Remove those explanatory comments from
command-helpers.ts and keep the logic self-explanatory through the existing
identifiers shouldDisableColors, chalk, and prettyJsonRenderOptions; if
clarification is still needed, prefer clearer naming or structure over comments.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a3ef274a-3eef-4553-b733-a6dade3735e6
📒 Files selected for processing (7)
src/commands/deploy/deploy.tssrc/commands/sites/sites-create.tssrc/commands/status/status-hooks.tssrc/commands/status/status.tssrc/commands/watch/watch.tssrc/utils/command-helpers.tstests/unit/utils/no-color.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
netlify/blueprints(manual)
Split from #8300 (3 of 9).
What
Honors the NO_COLOR convention: any non-empty
NO_COLORvalue disables ANSI colors — both inchalkoutput and in everyprettyjson.rendercall site (deploy,sites:create,status,status:hooks,watch), which bypassed chalk's existing--jsonguard.Measured:
NO_COLOR=1 netlify env --helpgoes from 30 ANSI escape sequences to 0.Why it helps agents
Agents consume CLI output through pipes and set
NO_COLORexpecting clean text; today they get ANSI noise they have to strip (or worse, parse around). This is the informal standard nearly every modern CLI honors.Testing
shouldDisableColors