rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[rush] rush alert should honor `-q` and `--json` and similar

Open stijnveenman opened this issue 6 months ago • 1 comments
trafficstars

Summary

When rush alerts is used, utilities that rely on output could fail if the alert is triggered. shouldRestrictConsoleOutput should probably be honored on rush alerts.

Repro steps

run any command that relies on output, like rush list --json | jq

Expected result: Only JSON should be written to STDOUT

Actual result: Rush alerts are written to stdout, resulting in an error

jq: parse error: Invalid numeric literal at line 4015, column 0

Details

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/rush globally installed version? 5.153.1
rushVersion from rush.json? 5.153.1
useWorkspaces from rush.json? undefined
Operating system? Mac / Linux
Would you consider contributing a PR? No
Node.js version (node -v)? 22.14.0

stijnveenman avatar May 13 '25 13:05 stijnveenman

Looks like this was an oversight when that feature was implemented. Should be a fairly easy fix.

iclanton avatar May 28 '25 18:05 iclanton

Hi! @iclanton I’d like to take this issue, could you please assign it to me?

Proposed approach:

  • Honor shouldRestrictConsoleOutput() for Rush alerts so -q / --quiet and --json suppress the alert banner.
  • Change site: libraries/rush-lib/src/cli/RushCommandLineParser.ts
    • Console restriction logic: https://github.com/microsoft/rushstack/blob/main/libraries/rush-lib/src/cli/RushCommandLineParser.ts#L205-L221
    • Alert invocation in onExecuteAsync(): https://github.com/microsoft/rushstack/blob/main/libraries/rush-lib/src/cli/RushCommandLineParser.ts#L255-L275
  • Minimal change (parser-level guard): if (!RushCommandLineParser.shouldRestrictConsoleOutput()) { await rushAlerts.printAlertsAsync(); }

Rationale:

  • Prevents alert output on stdout so commands like rush list --json | jq emit only JSON.
  • Keeps explicit rush alert behavior unchanged.

Tests:

  • Add/extend a test to assert no alert output when --json or -q is present, and JSON remains valid.

If this direction looks good, I’ll proceed from branch fix/5228-alert-honor-quiet-json. Thanks!

AryanBagade avatar Sep 03 '25 20:09 AryanBagade