Repository navigation
fix(constraints): floor-guard reference reads hunk lines as content and runs from the top - #614
Merged
addyosmani merged 1 commit intoOct 2, 2026
Conversation
…nd runs from the top Two follow-ups from the review on addyosmani#600, both already on main before it: - The diff walk treated any line starting with `---` or `+++` as a file header. Inside a hunk those lines are content. An added line that starts with `++` (`++n; // eslint-disable-line no-plusplus`) shows as `+++n; ...` and was dropped, so the suppression passed. An added line that starts with `++ ` was taken as a header, so the lines after it were filed under a made-up path and a removed assertion further down the same test file went unreported. A removed line starting with `--` never reached the removed list either. Headers are now read only between a file's `diff` line and its first `@@`. - Run from a subfolder, `git ls-files --others` listed only that subfolder's untracked files, relative to it, while `git diff` covers the whole tree from the top. An untracked suppression elsewhere in the repository was missed, and one inside the subfolder was reported under a different name from the tracked files. The guard now changes to `git rev-parse --show-toplevel` first, and exits 2 outside a work tree. The test gains six cases: five fail on main, and the sixth (outside a work tree) passes on both and covers the new exit-2 path; 28 pass. The test now also runs in the macOS/Windows matrix.
addyosmani
approved these changes
Oct 2, 2026
addyosmani
left a comment
Owner
There was a problem hiding this comment.
praise: exactly the follow-ups from #600, and the fix is the right shape: ---/+++ count as headers only between a diff line and the first @@, and the guard runs from the top of the work tree. Six tests, including both subfolder cases and the exit-2 path outside a repo. Merging.
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.
Follow-up to #600: the two issues from the review there, both already on main before it, plus the macOS/Windows matrix entry.
Lines inside a hunk read as headers. The diff walk treated any line starting with
---or+++as a file header. Inside a hunk those lines are content:++n; // eslint-disable-line no-plusplus+++n; ...++ n;, then an assertion removed further down the same test file+++ n;n;, exit 0--n; assert.equal(n, 0);from a test---n; ...Headers are now read only between a file's
diffline and its first@@.Run from a subfolder.
git ls-files --otherslists only the current directory's subtree, relative to it, whilegit diffcovers the whole tree from the top. Fromsub/, an untracked suppression at the top of the repository was missed (exit 0), and one insidesub/was reported asnew.jsrather thansub/new.js. The guard now changes togit rev-parse --show-toplevelfirst, so both lists share one root (a.constraintsignoreread by an adapted guard resolves from there too), and exits 2 outside a work tree, as the contract already says.Tests. Six new cases in
scripts/floor-guard-reference-test.js: five fail on main, and the sixth (outside a work tree) passes on both and covers the new exit-2 path. 28 pass. The file is added to thevalidate-platformsmatrix list.Run locally on Linux, also with
core.autocrlf=trueset system-wide as Git for Windows does; the macOS and Windows jobs on this PR are its first run there. The other CI steps pass locally.