Re: [Codenarc-user] Question about Using New Size Features
Brought to you by:
chrismair
From: Corum, M. <mc...@rg...> - 2010-11-15 22:08:40
|
This is what is confusing me. I’m using Grails so I’m not using (as in coding) any Ant task that I know of. Where would I put the rulesetfiles = MyRuleSet.groovy line? Would that go into BuildConfig.groovy or application.properties or somewhere else? Thanks, Mike From: chr...@wa... [mailto:chr...@wa...] Sent: Monday, November 15, 2010 3:36 PM To: Corum, Michael Cc: cod...@li... Subject: RE: [Codenarc-user] Question about Using New Size Features If you have included the "rulsets/size.xml" in your list of rulesets, then yes, you can do this configuration within "codenarc.properties". If you want to customize your rules and/or pull in from lots of different rulesets, then it makes sense to go ahead and create your own custom ruleset. Here is an example that just pulls in the basic and size rulesets. It turns off the ExplicitCallToMultiplyMethod and ExplicitArrayListInstantiation rules and configures maxLines property of the MethodSize rule. If you call this file "MyRuleSet.groovy" and put it somewhere on your classpath, then you can set your rulesetfiles (if using the Ant task) to "MyRuleSet.groovy". ruleset { ruleset('rulesets/basic.xml') { ExplicitCallToMultiplyMethod { enabled = false } ExplicitArrayListInstantiation { enabled = false } } ruleset('rulesets/size.xml') { MethodSize { maxLines = 8 } } } Chris "Corum, Michael" <mc...@rg...> 11/15/2010 04:24 PM To <chr...@wa...> cc <cod...@li...> Subject RE: [Codenarc-user] Question about Using New Size Features On the MethodSize thing, is there a way to do that only in the codenarc.properties file? Or do I have to set up a rulesets/size.xml? Can you provide example config files for this? I wasn’t able to figure that method out from the documentation so I went with the easier-to-understand codenarc.properties file. Thanks, Mike From: chr...@wa... [mailto:chr...@wa...] Sent: Monday, November 15, 2010 3:22 PM To: Corum, Michael Cc: cod...@li... Subject: Re: [Codenarc-user] Question about Using New Size Features Mike, The doNotApplyToClassNames property should specify the name of the class(es) containing the code that you want to ignore. So, set it to the name of the class containing the calls to multiply(). You can specify either a single class name or a comma-separated list of names. The names may optionally contain wildcard characters ('*' or '?'). The wildcard character '*' matches a sequence of zero or more characters in the input string. The wildcard character '?' matches exactly one character in the input string. Each class name(s) can be either a fully-qualified class name (including the package) or else a class name without a package. The ExplicitCallToMultiplyMethod rule and other similar methods are intended to encourage use of the corresponding operators -- in this case '*'. The code a.multiply(b) will produce exactly the same results under the covers as a * b. That being said, if you disagree with that convention, or just don't think it is important, feel free to disable the rule, as always. The rule configuration MethodSize.maxLines=8 is only relevant if you include the MethodSize rule in your ruleset. Are you including the "Size" ruleset ("rulesets/size.xml") or are you including that rule class directly when you configure a custom ruleset? Chris "Corum, Michael" <mc...@rg...> 11/15/2010 04:12 PM To <cod...@li...> cc Subject Re: [Codenarc-user] Question about Using New Size Features Sorry, I sent this before my test suite finished all the way. It didn’t work. Here is what I have in codenarc.properties: ExplicitCallToMultiplyMethod.doNotApplyToClassNames=java.lang.String,groovy.lang.GString It still flags any use of multiple on a string or GString. Any help would be much appreciated. Mike From: Corum, Michael [mailto:mc...@rg...] Sent: Monday, November 15, 2010 3:11 PM To: cod...@li... Subject: Re: [Codenarc-user] Question about Using New Size Features Please ignore this question. It was a GString rather than a java string. Once I put that in, this one worked. I’m still interested in the question of how to get the new features that were added in 0.11 to work properly. For instance, I put MethodSize.maxLines=8 in my codenarc.properties file and it isn’t catching any long methods. Thanks, Mike Corum From: Corum, Michael [mailto:mc...@rg...] Sent: Monday, November 15, 2010 2:56 PM To: cod...@li... Subject: Re: [Codenarc-user] Question about Using New Size Features Since upgrading from 0.6.1 to 0.11, I’m seeing lots of new violations. Many of them don’t really make sense. One example is the use of the “multiply” method on a string. The idea that this is a violation makes no sense. Here is some example code from a test where I was testing a long string: def longString = "Long String!".multiply(201) CodeNarc flags this with ExplicitCallToMultiplyMethod. Since using multiply is correct in this case (in fact, the recommended Groovy way of doing it), I wanted to turn this one off. So, I added the following line to codenarc.properties: ExplicitCallToMultiplyMethod.doNotApplyToClassNames=java.lang.String However, after running codenarc again, it still flags that line of code with ExplicitCallToMultiplyMethod. What can I do to make this work correctly? Michael Corum Consultant Software Architect RGA Reinsurance Company 1370 Timerlake Manor Parkway Saint Louis, MO 63017 T 636.736.7066 www.rgare.com _____________________________ This message is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone and return the original message to its sender. Thank you for your cooperation and assistance.------------------------------------------------------------------------------ Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev_______________________________________________ Codenarc-user mailing list Cod...@li... https://lists.sourceforge.net/lists/listinfo/codenarc-user ForwardSourceID:NT000CECDE ForwardSourceID:NT000CECFA |