makezero icon indicating copy to clipboard operation
makezero copied to clipboard

wrong detection when we use copy

Open MatheusNtg opened this issue 2 years ago • 1 comments

if we have the following situation

func someFunc() {
	slice1 := []int{1, 2, 3}
	slice2 := make([]int, len(slice1))
	copy(slice2, slice1)
	slice2 = append(slice2, 4)
}

The linter will identify a false positive, even though we filled the slice2 with copy builtin function.

MatheusNtg avatar Mar 22 '22 19:03 MatheusNtg

Thanks for the report. Currently, the tool does not try to detect this case so you'd have to add a nolint for it. Feel free to put up a PR if you think you can detect this sort of case generally and reliably. The current detection engine is very simple and does not try to follow the code, so there are a lot of ways that a user could generate a false positive with this tool. The belief behind this linter is that these cases aren't so common that using nolint isn't too much of an imposition to avoid the kind of error this detects, but that may not be true for your use case if you are doing a lot of copies.

ashanbrown avatar Mar 22 '22 19:03 ashanbrown