Skip to content

feat(cli): honor NO_COLOR#8331

Open
DavidWells wants to merge 1 commit into
mainfrom
split/no-color
Open

feat(cli): honor NO_COLOR#8331
DavidWells wants to merge 1 commit into
mainfrom
split/no-color

Conversation

@DavidWells

Copy link
Copy Markdown
Contributor

Split from #8300 (3 of 9).

What

Honors the NO_COLOR convention: any non-empty NO_COLOR value disables ANSI colors — both in chalk output and in every prettyjson.render call site (deploy, sites:create, status, status:hooks, watch), which bypassed chalk's existing --json guard.

Measured: NO_COLOR=1 netlify env --help goes from 30 ANSI escape sequences to 0.

Why it helps agents

Agents consume CLI output through pipes and set NO_COLOR expecting 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

  • New unit tests for shouldDisableColors
  • typecheck ✓ lint ✓ 407 unit tests ✓

Disables chalk colors and prettyjson colors (deploy, sites:create,
status, status:hooks, watch) when NO_COLOR is set, per no-color.org.
@DavidWells DavidWells requested a review from a team as a code owner July 6, 2026 17:52
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Console output now respects the NO_COLOR environment variable, disabling colors when requested.
    • Several command outputs have more consistent formatting across status, deploy, site creation, and watch flows.
  • Tests

    • Added coverage for NO_COLOR behavior and colorless output.

Walkthrough

This change introduces NO_COLOR environment variable support via a new exported shouldDisableColors() helper in command-helpers.ts, which now determines chalk color output and prettyJsonRenderOptions() behavior based on either the --json flag or NO_COLOR environment variable. Multiple command files (deploy, sites-create, status, status-hooks, watch) are updated to import and pass prettyJsonRenderOptions() into their prettyjson.render calls, standardizing JSON output formatting across these commands. A new unit test file validates shouldDisableColors() behavior and chalk's colorless initialization when NO_COLOR is set.

Estimated code review effort: 2 (Simple) | ~12 minutes

Suggested reviewers: aitchiss

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: honoring NO_COLOR in the CLI.
Description check ✅ Passed The description is directly about the same NO_COLOR CLI color-disabling changes and tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/no-color

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

📊 Benchmark results

Comparing with 3c41e72

  • Dependency count: 1,127 (no change)
  • Package size: 379 MB (no change)
  • Number of ts-expect-error directives: 359 (no change)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/utils/command-helpers.ts (2)

36-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate NO_COLOR/--json condition — extract shared helper.

The argv.includes('--json') || shouldDisableColors() expression is duplicated between chalk init (Line 39) and prettyJsonRenderOptions() (Line 43). Extracting a single shouldUseNoColor() 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 value

Doc 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 .ts files 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c41e72 and 9f5829d.

📒 Files selected for processing (7)
  • src/commands/deploy/deploy.ts
  • src/commands/sites/sites-create.ts
  • src/commands/status/status-hooks.ts
  • src/commands/status/status.ts
  • src/commands/watch/watch.ts
  • src/utils/command-helpers.ts
  • tests/unit/utils/no-color.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • netlify/blueprints (manual)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant