pkg / diff

Repository from Github https://github.compkg/diffRepository from Github https://github.compkg/diff

get rid of the module dependency on sergi/go-diff

mvdan opened this issue · comments

I understand that it's just used in a test, and that if a main package imports pkg/diff, it won't end up depending on sergi/go-diff at a package level.

However, it's still undesirable for pkg/diff to pull in such relatively heavy dependencies. Beyond go-diff itself, we also end up pulling testify and even a yaml library (!!!).

It's true that this will become less of a concern with lazy module loading. I don't think that's a satisfactory answer though, because it won't ship until at least 1.17 in six months, and people will keep using go 1.16 or earlier in their go.mod files for at least a year or two.

So, I think we should remove it. It seems to only be used in a single test, to show a diff when the unified diff tests fail. I get why we don't want to use our own code; if the diffs are broken, showing a broken diff in the output isn't good.

I see two reasonable options:

  1. Use the host's diff tool in that case, like what gofmt -d does.

  2. Just show the entire output as-is. The tests aren't large, and failures should be rare.

I also think that, until lazy module loading is widespread (in at least a year), we should really try to have zero module dependencies.