#475 header filter for code duplicate

Check (274)
Benjamin POCHAT


I try to make people use CheckStyle in my company.
Combined with Maven or Eclipse, this is a really good tool.

The main limitation I found is that I can't exclude "strict duplicate code" audit event according to a file header. Let me explain : we include in our projects some java code generated automatically by a tool. These generated files cannot be recognized by their names, but by a specific header. The problem is that a lot of duplicate code is detected by CheckStyle, wherease we can't change de way this auto-generated code is made.

I would be great to be able to exclude these file of duplicate code detection thnaks to their header.




  • Lars Kühne
    Lars Kühne

    Logged In: YES
    Originator: NO

    Most projects structure their build in a way that separates hand written code from generated files. For example, maven places all generated code unter the "target" directory, just like java byte code, etc. This means that you don't need to distinguish by name but you can distinguish by location: Only check stuff that is in the "hand written" part of the project directory.

    I guess the maven plugin does this by default (if it doesn't I think that's a bug in the plugin). In the Eclipse plugin you can control this as well.

    I hope you can restructure you project layout so you can use the above mechanisms. If not, you have very unusual requirements, and it's very unlikely that this feature wil be implemented in the standard distribution. But the good thing is that checkstyle is open source, and you can take our implementation (StrictDuplicateCodeCheck.java) and modify the code so that it suits your needs. Checkstyle has a plugin infrastructure so you can modify the configuration to use your implementation instead of the default one.

    Hope this helps,

  • Logged In: YES
    Originator: YES

    Thanks Lars for your quick response.
    I finally could identify the auto-generated files by their names. I hope the list of file name regexp will be stable enough in order this filtering method will be sustainable. If not, I will go deeper in the StrictDuplicate source code.

    Thanks a lot,