Repository navigation
Fix baseline duplicate replacements - #6872
LizunovSergey wants to merge 2 commits into
Conversation
Generated by 🚫 Danger |
|
Author of #6871. The anchor approach is the right call: an unchanged duplicate is the evidence that the group did not shift, which is exactly the distinction the old fallback could not make. Keeping the shift-tolerant path where no exact match survives leaves the intentional behaviour intact. One residual worth stating, not a request to change anything. When every duplicate in a group is replaced in the same run, no anchor survives, the group falls through to the shift-tolerant path, and the swap stays invisible. That is narrower than what #6871 reported — it needs the whole group to turn over at once — but it is the same shape, and it is better known now than discovered later. Reason and line text remain the only keys on that path, so the residual is bounded by how generic those are. Checks are green apart from the ones waiting on maintainer approval. |
|
Thanks — and the residual is real. Worth stating why it stays open rather than getting folded in here. The anchor is the only evidence available. Reason and line text are the whole key on that path, so a So it is bounded the way you describe: it needs the whole group to turn over at once, and it only |
438b3f0 to
945fb2c
Compare
|
Agreed, and that is the right line to draw. A key stronger than reason plus line text is a different change from this one; folding it in here would report every shifted group as new, which is the false positive the shift-tolerant path exists to avoid. This PR closes #6871 as reported. The whole-group-turnover case is worth its own issue against a stronger key, not a rider on this one. |
|
Thanks for picking this up. I think the anchor heuristic introduces a false positive for a common edit pattern: a shift that only moves some of the duplicates. Two identical A related case: a uniform 10-line shift of {10, 20} produces {20, 30}, which is exactly the input of Repro, using the PR's helpers: This passes on |
|
|
||
| #expect(baseline.filter(currentViolations).isEmpty) | ||
| } | ||
|
|
There was a problem hiding this comment.
The repro from my comment, as a suggestion. It passes on main and fails on this branch.
| @Test(.temporaryDirectory) | |
| func ignoresShiftBetweenDuplicateViolations() throws { | |
| let sourceFilePath = URL.cwd.appending(path: "Example.swift", directoryHint: .notDirectory) | |
| try Self.lines(withDuplicatesAt: [10, 20]).joined(separator: "\n").write( | |
| to: sourceFilePath, | |
| atomically: true, | |
| encoding: .utf8 | |
| ) | |
| let baseline = Baseline(violations: Self.duplicateViolations(at: [10, 20], in: sourceFilePath)) | |
| try Self.lines(withDuplicatesAt: [10, 22]).joined(separator: "\n").write( | |
| to: sourceFilePath, | |
| atomically: true, | |
| encoding: .utf8 | |
| ) | |
| let currentViolations = Self.duplicateViolations(at: [10, 22], in: sourceFilePath) | |
| #expect(baseline.filter(currentViolations).isEmpty) | |
| } | |
|
@Akhrameev you are right on both points, and thanks for the repro. A uniform 10-line shift of {10, 20} gives the filter exactly the input of the case in #6871: same rule, same reason, same line texts, lines {20, 30}. So no filter keyed on those fields can report one and ignore the other. The anchor heuristic also flags your partial shift, which Closing this PR. I added a note on #6871. |
Fixes #6871
Summary
Root cause
After exact matches are removed, the fallback comparison used only the number of remaining violations with the same text and reason. A replacement could therefore be hidden by an unmatched baseline duplicate with the same key.
An unchanged duplicate now acts as an anchor: if the remaining counts are equal within that group, the unmatched current violations are reported. A group with no exact match still follows the existing shift-tolerant behavior.
Tests
swift test --filter BaselineTests