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

オープン 初心者向け
#195 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
87/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go

調査の方向性

internal/diffx/diffx.go の Stat 周辺と、issue に記載された diff 生成の動作を読みます。次に diffx のテストを実行し、削除された -- 行、追加された ++ 行、ファイルヘッダーのケースを追加します。Stat を更新し、ファイルヘッダーをスキップしながら、ハンク内の変更行を数えるようにします。受け入れ基準を満たし、make test-short が成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Go
スター
0
フォーク
1
平均マージ
8時間 14分
マージ済み PR(30日)
3

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TMHSDigital/Spackle のほかの issue

TMHSDigital/Spackle の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。