migra icon indicating copy to clipboard operation
migra copied to clipboard

would like to have option to ignore trailing whitespaces

Open mk2s opened this issue 7 years ago • 1 comments

I ran into this today and it caught me by surprise. My old function definition had a trailing white space while the new definition had none. In my mind this should not be a change, but it registered as one. And because that function was used by many views it showed as all my views needed to be dropped and re-added. To say the least this was confusing. Having an option like --ignore-trailing-whitespaces would have cut down on the noise. I'll try to provide test cases. I was using postgresql 9.5.12 on ubuntu 16.04

mk2s avatar May 01 '18 20:05 mk2s

I am not very familiar with Python, but I was able to solve this by modifying changes.py as below:

import re
def normalize_trailing_whitespaces(functions):
    for k, v in functions:
        v.definition = re.sub(r"\r?\n[\s\t]*", "\n", v.definition)

Added these 2 lines on Changes.__getattr__(self, name) after af and bf are initialized https://github.com/djrobstep/migra/blob/0aa1127d2f9d27f991c36f78f174748789f3dc95/migra/changes.py#L184

normalize_trailing_whitespaces(af)
normalize_trailing_whitespaces(bf)

lpfeup avatar Jul 23 '18 16:07 lpfeup