@diegovelasquezweb/a11y-engine 0.11.42 → 0.11.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -165,16 +165,31 @@ function buildPatternAiInput({ finding, candidate, projectHints }) {
|
|
|
165
165
|
? finding.context.split("\n").map((l) => l.trim()).filter(Boolean)
|
|
166
166
|
: [];
|
|
167
167
|
const matchPrefix = rawMatch.slice(0, 30);
|
|
168
|
-
|
|
168
|
+
|
|
169
|
+
// Declare effectiveLineIndex first so it can be used when computing currentAtOriginal.
|
|
170
|
+
let effectiveLineIndex = originalLine !== null ? originalLine - 1 : -1;
|
|
171
|
+
|
|
172
|
+
// The current content at the original line position — use this to pin the anchor
|
|
173
|
+
// to THIS specific element rather than a sibling with a similar match prefix.
|
|
174
|
+
const currentAtOriginal = effectiveLineIndex >= 0
|
|
175
|
+
? (fileLines[effectiveLineIndex] || "").trim()
|
|
176
|
+
: "";
|
|
177
|
+
// Prefer a context line that exactly matches the current file content at originalLine.
|
|
178
|
+
// This disambiguates siblings (e.g. two inputs with placeholder=) when the file has
|
|
179
|
+
// not yet been modified. Falls back to the longest context line for post-shift cases
|
|
180
|
+
// where the original position now holds different content (lines were inserted before it).
|
|
181
|
+
const exactContextMatch = matchPrefix
|
|
182
|
+
? contextLines.find((l) => l === currentAtOriginal && l.includes(matchPrefix)) || null
|
|
183
|
+
: null;
|
|
184
|
+
const longestContextMatch = contextLines.reduce((best, line) => {
|
|
169
185
|
if (!matchPrefix || !line.includes(matchPrefix)) return best;
|
|
170
186
|
return !best || line.length > best.length ? line : best;
|
|
171
187
|
}, null);
|
|
172
|
-
const anchor =
|
|
188
|
+
const anchor = exactContextMatch || longestContextMatch || matchPrefix;
|
|
173
189
|
|
|
174
190
|
// The file may have been modified by a previous sequential fix (lines shifted).
|
|
175
191
|
// Search for the actual current line containing the anchor instead of
|
|
176
192
|
// relying solely on the original line number from the scan.
|
|
177
|
-
let effectiveLineIndex = originalLine !== null ? originalLine - 1 : -1;
|
|
178
193
|
if (anchor && effectiveLineIndex >= 0) {
|
|
179
194
|
const lineAtOriginal = (fileLines[effectiveLineIndex] || "").trim();
|
|
180
195
|
if (!lineAtOriginal.includes(anchor)) {
|