dealertrack / flake8-diff

Run flake8 across a set of changed files and filter out violations occurring only on the lines that were changed.
MIT License
20 stars 8 forks source link

Differentiate between new lines and modified lines #31

Open jayvdb opened 8 years ago

jayvdb commented 8 years ago

When working on a codebase which has violations which are baked in, such as CamelCase method names, modifications of those lines are not new violations, and 'fixing' them would create new bugs part of any release other than a major release.

It would be nice if there was an option to omit modified lines from the reported errors.

miki725 commented 8 years ago

What do you mean "omit modified lines from the reported errors"? The purpose of flake8-diff is to output errors only for the modified lines. Are you trying to do something else?

jayvdb commented 8 years ago

I'd like an option to only report errors in chunks of lines that are added ; i.e. the vcs diff program is not able to match the lines with lines in the pre-existing code.

miki725 commented 8 years ago

can you give an example?

jayvdb commented 8 years ago

I'd like it to skip checking modified line in the following, and report errors in the two new lines.


-old line
+modified line

+new line 1
+new line 2
miki725 commented 8 years ago

This can be customized for git in https://github.com/dealertrack/flake8-diff/blob/master/flake8diff/vcs/git.py#L67 although not sure what the parameter should be. Also not sure how it would be implemented for other backends like hg which does not have equivalent implementation. Instead it manually finds the changed files. https://github.com/dealertrack/flake8-diff/blob/master/flake8diff/vcs/hg.py#L57-L69

jayvdb commented 8 years ago

The git diff --diff-filter supports listing only added files, but it does not support listing only files with lines added.

If I was implementing this, I would not be looking at modify changed_files.

Instead I would be modifying changed_lines to only list lines added. This would mean that some files listed by changed_files would not have any lines added, as they only had lines modified. Is that approach reasonable? If this sounds like a feature you'd be willing to accept, I am happy to have a go at coding it, as I would like to use this feature for https://github.com/wikimedia/pywikibot-core (pending change https://gerrit.wikimedia.org/r/#/c/257537/).

miki725 commented 8 years ago

sounds reasonable to me. just to clarify - you would like to ignore modified lines however Im not sure how would that work on a file where both lines are added and modified. either way you are more then welcome to try to implement this. having some concrete example might help with figuring out all the edge cases