diffx.Stat skips changed lines whose text starts with "++" or "--"

Open Beginner friendly
#195 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
87/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go

Research direction

Read internal/diffx/diffx.go around Stat and the diff generation behavior described in the issue; then run the diffx tests and add cases for removed -- lines, added ++ lines, and file headers. Update Stat so it counts changed lines inside hunks while skipping file headers. Done when the acceptance criteria pass and make test-short succeeds.

Written by the indexing model from the issue text.

Description

bug good first issue severity: low

Summary

Stat treats every line starting with +++ or --- as a file header, so an added line whose text starts with ++ and a removed line whose text starts with -- are not counted. The 400-line limit on a model-written patch is computed from this count.

Where

  • internal/diffx/diffx.go:103-110 (Stat)
  • internal/agent/fixcheck.go:44, :194 (added + removed against maxPatchLines = 400)

Details

unified writes an added line as "+" + text and a removed one as "-" + text. An added ++i; becomes +++i;; a removed SQL, Lua or Haskell comment -- note, a YAML --- separator or a --flag \ continuation line becomes --- note. Both match the header case and are skipped.

Impact

The size of a fix is undercounted, so the patch size limit does not hold for such lines; a patch that removes or adds many of them can be far over the limit and still be accepted.

Steps to reproduce

  1. Call diffx.Stat(diffx.Unified("a.sql", "-- one\n-- two\nSELECT 1;\n", "SELECT 1;\n")).
  2. It returns (0, 0); the diff removes two lines.

Suggested fix

Count by position, not by prefix alone: skip --- / +++ only for the two lines that follow a diff --git line (or its mode line) and precede the first @@; inside a hunk count every + and - line.

Acceptance criteria

  • Stat(Unified("a.sql", "-- one\n-- two\nSELECT 1;\n", "SELECT 1;\n")) returns 0 added, 2 removed
  • An added ++i; line counts as 1 added
  • File headers are still not counted

Getting started

  • Relevant files: internal/agent/fixcheck.go, internal/diffx/diffx.go
  • How to run tests: make test-short (Unix) or .\make.ps1 test-short (Windows PowerShell); make lint before you call it done
  • Related docs: CONTRIBUTING.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 50e92ec. Severity: low. Effort: S. audit-key: bug|internal/diffx/diffx.go|Stat

Dominant language
Go
Stars
0
Forks
1
Avg merge
8h 14m
Merged PRs (30d)
3

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TMHSDigital/Spackle

All issues in TMHSDigital/Spackle

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.