Skip to content

fix: address bugs found in a full-codebase audit - #77

Merged
coldhighsun merged 10 commits into
mainfrom
fix/code-audit-fixes
Sep 30, 2026
Merged

coldhighsun merged 10 commits into
mainfrom
fix/code-audit-fixes

Conversation

@coldhighsun

Copy link
Copy Markdown
Owner

Summary

Fixes from a read-through audit of the whole codebase. Findings were prioritized and the real ones fixed; each commit covers one area and adds or updates tests.

CLI behavior

  • Repeatable options no longer swallow the path. sloc -e "*.md" src used to treat src as another exclude glob and silently analyze .. AllowMultipleArgumentsPerToken is removed, so each value needs its own flag (-e a -e b). Behavior change: -e a b no longer feeds b to --exclude. Command construction moved into SlocCommandFactory so this is covered by tests.
  • Ctrl+C removes snapshot temp directories for --git-hash / --compare-to, including during extraction.
  • --min-comment-pct warns when no files were analyzed (still exits 0) and prints values precisely, so 4.96% is no longer reported as "5.0% below 5.0%".
  • --watch fails with a clear error when stdout is redirected, and keeps the final table on exit.
  • Invalid --baseline "" / --list-file "" exit with the path-error code instead of an unhandled exception. --jobs 0 still means "automatic".
  • Temporary snapshot paths no longer leak into skip reasons; --sort rejects undefined values; help text for --sort / --output is corrected.

Git handling

  • rev:./path / rev:../path tree-ishes are resolved from the hint directory, matching the tree-prefix bookkeeping.
  • The cat-file --filters process is killed if the temp file cannot be created.
  • An empty gitdir: in a .git file is treated as unusable instead of throwing.
  • [attr] macros accept blanks between the prefix and the name.

Language rules

  • '"' is a character literal in Rust, Scala, Haskell, F# and OCaml.
  • Backslash escapes are honored in Dart, Groovy and Starlark triple-quoted strings.
  • Haskell operators such as --> and |-- are no longer line comments.

Output

  • CSV neutralizes a leading carriage return; JSON percentages round half away from zero.
  • LiveAggregator uses Lock for its gate.

Not changed

Reported but left alone: a backslash in file names on Linux/macOS, .git/info/attributes support, GitWorkTree.Find stopping at a stray .git directory, --unique deduplicating across languages, and '"' handling for Zig/Nim/Elm.

Test plan

  • dotnet build Sloc.slnx (0 warnings, 0 errors)
  • dotnet test Sloc.slnx (798 passed)
  • New classifier and parsing tests fail without their fixes
  • Not verified: Ctrl+C cleanup and --watch on a real terminal; classifier benchmarks were not re-run

…in language rules

Treat '"' as a character literal in Rust, Scala, Haskell, F# and OCaml, honor
backslash escapes in Dart, Groovy and Starlark triple-quoted strings, and stop
Haskell operators such as --> and |-- from being classified as line comments.
Git allows blanks after [attr], so the name is the next token rather than a
separate attribute state on a bogus pattern.
A .git file containing only 'gitdir:' made Path.GetFullPath throw instead of
being ignored.
…xtraction

Run the rev-parse in the hint directory so ./ and ../ resolve the way the tree
prefix bookkeeping assumes, kill the cat-file process when the temp file cannot
be created, and expose DeletePendingTempRoot so an interrupt can remove a
partially extracted snapshot.
Math.Round used banker's rounding, so 6.25 became 6.2 while the table showed 6.3.
Drop AllowMultipleArgumentsPerToken so 'sloc -e "*.md" src' analyzes src instead
of treating it as another exclude glob. Move command construction into
SlocCommandFactory so parsing is testable, validate --sort, guard against a
missing console when setting the output encoding, and fix the --sort/--output
help text.
…aths in skip reasons

Warn when no files were analyzed instead of silently passing, print the values
with enough precision that 4.96% is not reported as '5.0% below 5.0%', and
rewrite temporary snapshot paths embedded in skip reasons back to git paths.
…ths as errors

Register cleanups for --git-hash and --compare-to extractions so an interrupt
deletes the temp directory, reject --watch when stdout is redirected and keep
the final table on exit, and map empty or malformed --baseline and --list-file
paths to the path-error exit code instead of an unhandled exception.
@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

@coldhighsun
coldhighsun merged commit dce5b85 into main Sep 30, 2026
10 checks passed
@coldhighsun
coldhighsun deleted the fix/code-audit-fixes branch September 30, 2026 09:54
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