views:

71

answers:

1

I've been looking into checkstyle recently as part of some research into standard coding conventions. Though it seems like it is perfectly suitable for brand new projects, it seems to have a huge barrier to adoption for already existing projects as it doesn't seem to supply a method of only checking new or edited code. Maybe I'm wrong?

If you have a codebase that has never had a coding standard it could be a massive effort to get the whole codebase inline with a standard all at once. Allowing it to be done incrementally over time as code naturally evolves seems like a more reasonable approach. But it doesn't seem like a possibility with checkstyle.

I assume this would have to be a tie in with a source control system in order to be possible. Is that possible with Checkstyle or is there another tool that can provide this functionality?

+1  A: 

As far as I known, Checkstyle is meant to analyze source, without considering its history or revisions.

To add that kind of feature means script checkstyle analysis to feed it with the exact sub-set of files representing the delta.

But then, certain kind of checks would be likely to fail or to miss in their analysis, like duplicate code check.

So for that kind of incremental analysis, you not only need to restrict the set of sources, but also the set of rules you want to enforce, for some of those rules only make sense on the all sources.


So, why couldn't you run a full check on each file and then filter results based on changes managed by your source control system? Anything like that exist?

Not to my knowledge, especially with plugin like eclipse-cs for eclipse: it they analyze a file, they will display all warnings, even though the source control mentions the file has not changed since a given revision.

Only an external script would be able to do this:
The principle is simple (although it could be a bit slow at execution time):

  • for each file, do a diff to check if modification have been made
  • if yes,
    • do a svn blame to annotate lines with the revision number which contained the last change.
    • Then analyze the file with checkstyle.
  • The script can then filter the warning for the line being currently modified (or for all the lines modified after a given revision).
VonC
It has the functionality to check against just one source file. So, why couldn't you run a full check on each file and then filter results based on changes managed by your source control system? Anything like that exist?
Fostah