Question: I am currently working on a source code generation tool. To make sure that my changes do no introduce any new bugs, a `diff` between the output of the program before and after my changes would theoretically be a valuable tool.

However, this turns out to be harder than one might think, because the tool outputs lines where the order does not matter (like `import` statements, function declarations, …) in a semi-randomly ordered way. Because of this, the output of `diff` is cluttered with many changes that are in fact only lines moved to another position in the same file.

Is there a way to make diff ignore these moves and only output the lines that have really been added or removed?

Answer: 
You could do a simple diff, store the result somewhere (to avoid another diff), loop through the lines in either version, then remove those from the other side.

This spawned a [separate project](https://github.com/l0b0/diff-ignore-moved-lines) for the working code. [The code.](https://github.com/l0b0/diff-ignore-moved-lines/blob/master/diff-ignore-moved-lines.sh)
It sounds like you have control over the tool. Then make its output predictable: instead of emitting declarations in a semi-random order, use (say) alphabetical order as a last resort. This will not only have the benefit of removing useless cruft from diffs, but also of making the tool's output easier to read and verify for a human being.