inversionHint detects the case where the caller swapped `search` and `replace`: search did not match but replace appears in the file.
( content string, contentLines []string, replace string, replaceLines []string, trimRight, trimAll func(a, b string) bool, )
| 1220 | // inversionHint detects the case where the caller swapped `search` |
| 1221 | // and `replace`: search did not match but replace appears in the file. |
| 1222 | func inversionHint( |
| 1223 | content string, |
| 1224 | contentLines []string, |
| 1225 | replace string, |
| 1226 | replaceLines []string, |
| 1227 | trimRight, trimAll func(a, b string) bool, |
| 1228 | ) string { |
| 1229 | if len(replaceLines) == 0 { |
| 1230 | return "" |
| 1231 | } |
| 1232 | |
| 1233 | lines := substringMatchLines(content, replace) |
| 1234 | if len(lines) == 0 { |
| 1235 | lines = lineEquivalentMatchLines(contentLines, replaceLines, trimRight) |
| 1236 | } |
| 1237 | if len(lines) == 0 { |
| 1238 | lines = lineEquivalentMatchLines(contentLines, replaceLines, trimAll) |
| 1239 | } |
| 1240 | if len(lines) == 0 { |
| 1241 | return "" |
| 1242 | } |
| 1243 | return fmt.Sprintf( |
| 1244 | "Did you swap %q and %q? Your replace string appears at line %s", |
| 1245 | "search", "replace", formatLineList(lines), |
| 1246 | ) |
| 1247 | } |
| 1248 | |
| 1249 | // substringMatchLines returns the 1-based line numbers where needle |
| 1250 | // occurs in content as a byte-for-byte substring, including |
no test coverage detected