[Codenarc-user] Advice on Violation Messages
Brought to you by:
chrismair
From: Hamlet D'A. <ham...@gm...> - 2011-03-25 13:46:07
|
Hi everyone, I have a few requests to make of anyone implementing a CodeNarc rule: 1) Every violation should have a text message. This makes a big difference when reading a CodeNarc report. 2) Violation messages should explain what specifically is wrong. For instance, try to include the variable name/field name/class name in the message so the reader can know more what went wrong. Use ASTNode.getText() to get the text for bits of AST to print out. 3) *Always* print the class name in the message. This makes it easy to add this class to the "classToIgnore" standard property. 4) Write your own ASTNode.getText() if the default value is not correct, missing, or just bad. For instance, ClosureExpression.getText() returns the String "<not supported for ClosureExpression>". The best way to fix this is by adding this code to your rule: ClosureExpression.metaClass.getText = { return ' { -> ...} ' } This is important because I can then come back later and merge your code into Groovy-core, making the language just a little better. That is all. Thank you. -- Hamlet D'Arcy ham...@gm... |