This is a very simple trick.
The problem is actually due to the last stitch of the row below, which can tend to be looser than the you'd like it to be.
So, on a knit row - put the RH needle into the first stitch as usual -
- and then pull the working yarn up, quite firmly.
This will pull the loop of the stitch from the row below up too, up and partly across the LH needle, taking the slack out of it. Put your finger on it for a moment, just to keep it in place whilst you finish the stitch.
Now take the yarn back down to its usual position, and knit the stitch as usual.
At the beginning of a purl row, it is even simpler. Wrapping the yarn to purl a stitch brings the yarn up at the front - so just make sure that for that first stitch you bring it up firmly.
Result, nice neat edges. I promise.