during my nightly builds I also let PMD have a look at my code. Now the PMD rule ShortVariable complains about all my "id"-fields in my domain-objects that the variable name is too short. Is there any (easy) way to tell PMD to ignore any variable name which is called "id"?
I don't want to exclude the rule per se and I'm also too lazy to write after every id-field a "//NOPMD". In the official PMD documentation I couldn't find any information about altering the rule. The only thing I can think of is writing my own rule. But isn't there any easier way? (If not, has someone wrote such a rule already? ;-)
This wouldn't be the first time I missed the obvious, but what is "PMD"?
You might want to rethink your short names, though. Some ORM systems focus on variables whose named end with "id" and attempt to identify them as primary keys. The convention is for something like "delinquentsId" to be the key for the "delinquents" table. When you have a lot of foreign keys, this can be a big help in avoiding confusion.
Some things like loop variables don't really need long descriptive names, but items of larger scope do benefit. For one thing, it's easier to track down how they're being used when using an editor search if the name is both unique and long enough that you won't get false hits because it's part of a common larger usage - like naming a variable "ng" in a class full of String methods.
Of course, who wants to type long windy names? Fortunately the refactoring that most modern IDEs provides means that you can write your code with a variable named "ix" and then refactor it to "boyWhoDoesntKnowWhatAHrungIsOrWhyItShouldCollapseOnHisPlanet". And not accidentally zap the variable named "sixPence".
Customer surveys are for companies who didn't pay proper attention to begin with.
Mea culpa. PMD is a static code analyzer (http://pmd.sourceforge.net/) similar to FindBugs (http://findbugs.sourceforge.net/).
I am aware of the shortcomings of short variable names but it was a conscious decision that the variable name "id" is allowed in our code. Thanks for the reply anyway, Tim.
//VariableDeclaratorId[string-length(@Image) < 3]
[not((ancestor::FormalParameter) and (ancestor::TryStatement))]
As a developer, this makes it changeable. Or more specifically to not run their rule and use your own similar rule. One that is basically what is here with an additional condition. Not the easiest change in the world if you aren't familiar with extending PMD rules (or XPath), but likely easier than adding //NOPMD all over.