Skip to content

feat(cli): show scan duration in terminal summaries#141

Merged
flaglint merged 4 commits into
flaglint:mainfrom
100NikhilBro:feat/show-scan-duration
Jul 1, 2026
Merged

feat(cli): show scan duration in terminal summaries#141
flaglint merged 4 commits into
flaglint:mainfrom
100NikhilBro:feat/show-scan-duration

Conversation

@100NikhilBro

@100NikhilBro 100NikhilBro commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds scan duration information to terminal summaries for both scan and audit commands.

Changes

  • Added a reusable formatDuration() helper

  • Updated scan command summary to include:

    • formatted duration
    • scanned file count
  • Updated audit command summary to include:

    • formatted duration
    • scanned file count
  • Added CLI test coverage for duration formatting

  • Added audit test coverage for duration formatting

Verification

Test Files 21 passed (21)
Tests 463 passed (463)

This change only affects terminal summary output and does not modify report formats or scanner behavior.

Summary by CodeRabbit

  • New Features
    • Updated scan and audit completion messages to show a human-readable, formatted duration (instead of raw milliseconds).
    • Audit completion now also includes the number of scanned files.
  • Tests
    • Updated CLI and audit tests to match the new duration text and related stdout/stderr output expectations.
  • Chores
    • Added a shared formatDuration(ms) utility to standardize command timing display.

Signed-off-by: Nikhil Gupta <100pranjalgupta@gmail.com>
@100NikhilBro 100NikhilBro requested a review from Krishan27 as a code owner June 21, 2026 15:22
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 18eb4754-ef8a-45fc-8a9f-b990cced6366

📥 Commits

Reviewing files that changed from the base of the PR and between a841bbb and 9d8c109.

📒 Files selected for processing (2)
  • src/commands/audit.ts
  • src/commands/utils/format-duration.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/commands/utils/format-duration.ts
  • src/commands/audit.ts

📝 Walkthrough

Walkthrough

A new formatDuration helper formats millisecond values as Xms or X.Xs. The scan and audit completion messages now use that helper and include scanned file counts. Tests were updated to assert the new stderr text and duration format.

Changes

Human-readable duration formatting

Layer / File(s) Summary
formatDuration utility
src/commands/utils/format-duration.ts
Adds a helper that formats milliseconds as ms below 1000 and seconds with one decimal place at 1000 and above.
Scan and audit completion messages
src/commands/scan.ts, src/commands/audit.ts
Imports formatDuration and uses it in the final success messages, replacing raw millisecond text and appending scanned file counts.
Test assertions for formatted duration
src/commands/tests/audit.test.ts, src/commands/tests/cli.test.ts
Updates stderr assertions to match the new duration format and the revised “Scan complete” summary text.

Estimated code review effort: 1 (Trivial) | ~4 minutes

Possibly related PRs

  • flaglint/flaglint-js#200: Modifies the same CLI reporting paths in src/commands/scan.ts and src/commands/audit.ts, including completion-message output and stderr routing.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding scan duration to CLI terminal summaries.
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 unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/commands/utils/format-duration.ts (1)

1-7: 💤 Low value

Consider adding input validation for robustness.

The function doesn't validate that ms is a non-negative, finite number. While the current callers (scan duration measurements) should always provide valid values, defensive validation would prevent unexpected output if the function is reused elsewhere.

🛡️ Optional: Add input validation
 export function formatDuration(ms: number): string {
+  if (!Number.isFinite(ms) || ms < 0) {
+    return "0ms";
+  }
+
   if (ms < 1000) {
     return `${Math.round(ms)}ms`;
   }

   return `${(ms / 1000).toFixed(1)}s`;
 }
🤖 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/commands/utils/format-duration.ts` around lines 1 - 7, The formatDuration
function lacks input validation and does not check whether the ms parameter is a
non-negative, finite number, which could lead to unexpected output if the
function is reused with invalid inputs. Add validation at the beginning of the
formatDuration function to ensure the ms parameter is a valid non-negative
finite number, and throw an appropriate error or return a default value if
validation fails.
🤖 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.

Inline comments:
In `@src/commands/tests/audit.test.ts`:
- Line 121: The regex pattern in the expect statement for r.stderr is checking
the output of formatDuration but does not account for decimal milliseconds.
Update the regex pattern to allow optional decimal values in the milliseconds
portion (e.g., 123.456ms) by making the decimal part optional after the integer
digits in the milliseconds alternative. The seconds pattern already handles
decimals correctly, so only the milliseconds pattern needs to be updated to
include an optional decimal component.

In `@src/commands/tests/cli.test.ts`:
- Line 113: The regex pattern in the expect statement for stderr matching at
line 113 does not account for decimal milliseconds that formatDuration could
produce. Update the regex pattern from `/\d+ms|\d+\.\d+s/` to handle both
integer and decimal milliseconds (e.g., 123ms or 123.456ms) in addition to the
already-supported decimal seconds format. Modify the milliseconds portion of the
regex to make the decimal part optional, allowing it to match patterns like
\d+\.?\d*ms to capture both whole and decimal millisecond values.

In `@src/commands/utils/format-duration.ts`:
- Around line 2-3: In the format-duration.ts file, the milliseconds output in
the condition where ms < 1000 is not rounding decimal values to integers. This
causes the output to potentially return decimal milliseconds (e.g.,
`123.456ms`), which does not match the test regex pattern expecting integer
milliseconds and is inconsistent with how seconds are formatted. Round the ms
value to an integer before including it in the return string template to ensure
both consistency in formatting and compatibility with the existing test regex
patterns in cli.test.ts and audit.test.ts.

---

Nitpick comments:
In `@src/commands/utils/format-duration.ts`:
- Around line 1-7: The formatDuration function lacks input validation and does
not check whether the ms parameter is a non-negative, finite number, which could
lead to unexpected output if the function is reused with invalid inputs. Add
validation at the beginning of the formatDuration function to ensure the ms
parameter is a valid non-negative finite number, and throw an appropriate error
or return a default value if validation fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9fcc5bf7-3193-47e1-abdf-47d8719d19de

📥 Commits

Reviewing files that changed from the base of the PR and between d66ef74 and 076dd95.

📒 Files selected for processing (5)
  • src/commands/audit.ts
  • src/commands/scan.ts
  • src/commands/tests/audit.test.ts
  • src/commands/tests/cli.test.ts
  • src/commands/utils/format-duration.ts

Comment thread src/commands/tests/audit.test.ts
Comment thread src/commands/tests/cli.test.ts
Comment thread src/commands/utils/format-duration.ts Outdated
@100NikhilBro

Copy link
Copy Markdown
Contributor Author

Hi @Krishan27 ,

I've synced the branch with the latest main, resolved the merge conflict, and all CI checks are now passing.

Please let me know if you'd like any changes regarding the CodeRabbit suggestions or anything else in the implementation. Happy to update the PR if needed.

Thanks for your time and review.

@100NikhilBro

Copy link
Copy Markdown
Contributor Author

Hi @Krishan27, @flaglint

I've synced this branch with the latest main, resolved the merge conflict, and pushed the updated branch.

All CI checks and the full test suite are passing after the merge.

The PR should now be up to date. If you'd like any changes, including addressing the earlier CodeRabbit suggestions, I'm happy to update it.

Thanks for your time and review.

…mary

- formatDuration: add Math.round() so decimal inputs (e.g. from high-res
  timers) produce clean integer output like 42ms rather than 42.456ms.
  Fixes the test regex /\d+ms/ which expects no decimal point.
- audit.ts: swap process.stderr.write → stderrInfo on the Audit complete
  summary line so --quiet suppresses it, consistent with scan.ts.

Signed-off-by: Krishan Kant Sharma <krishansharma0327@gmail.com>
@flaglint flaglint merged commit 69643b5 into flaglint:main Jul 1, 2026
10 checks passed
@flaglint

flaglint commented Jul 1, 2026

Copy link
Copy Markdown
Owner

@100NikhilBro /lgtm merged

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.

3 participants