fix: guard zero category totals in --percent tabular output - #746
Merged
boyter merged 1 commit intoAug 11, 2026
Merged
Conversation
The wide (fileSummarizeLong) and short (fileSummarizeShort) --percent rows divided each category total with no zero guard, so a project whose files have no blank/comment/complexity lines printed NaN% for those columns. The JSON path (addLanguagePercentages) and the Complexity/Lines calc already guard total != 0; only the tabular percentage rows were inconsistent. $ scc --percent a.json JSON 1 1 0 0 1 0 Percentage 100.0% 100.0% NaN% NaN% 100.0% NaN% Factor the division into a pct(value,total) helper that returns 0 for total==0, matching the JSON behaviour; each empty category now reports 0.0%. Regression test feeds a file with Blank=Comment=Complexity=0 and asserts no NaN in either the short or the wide output.
Owner
|
Odd. I thought I had caught all of those. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The wide (
fileSummarizeLong) and short (fileSummarizeShort)--percentrows divide each category total with no zero guard. A project whose files have no blank/comment/complexity lines therefore printsNaN%for those columns:The sibling JSON path (
addLanguagePercentages) and theComplexity/Linestotal both already guardtotal != 0— only the tabular percentage rows were inconsistent.Fix
Factor the division into a
pct(value, total)helper that returns0whentotal == 0, matching the JSON behaviour; each empty category now reports0.0%.Test plan
go test ./...— green, including a newTestPercentNoNaNOnZeroCategorythat feeds a single file withBlank=Comment=Complexity=0and asserts the short and wide output contain0.0%and noNaN. On master the same input emitsNaN%(the test fails).I licence this contribution under the MIT licence.