[Codenarc-developer] CodeNarc rulesets - even necessary?
Brought to you by:
chrismair
From: Chris M. <chr...@ea...> - 2011-02-13 01:49:45
|
Hamlet, I am still looking into the possibilities for extending the ruleset configuration options. As I mentioned before, my goal was to extend the Groovy Ruleset DSL to allow configuring rules by only specifying the rule name (and not requiring the rule class or a ruleset), e.g. ruleset { CatchThrowable(priority:1) EqualsAndHashCode(priority:3) MethodCount { doNotApplyToClassNames = ‘*Test, *TestCase’ } UnnecessaryConstructor() } As long as I can determine the rule class for a specific rule name, I can modify the Groovy RuleSet DSL to support that syntax. My first thought was introducing a @Rule annotation for the rule implementations. That might be the cleanest, but I am not sure how to do the annotation processing. It looks like Java 1.6 includes much better support for annotation processing, but I am not willing to mandate Java 1.6. So, after that, the best I can come up with is to retain a "registry" of all rules, indexed by name. Perhaps that means configure all rules; maybe in a “codenarc-base-rules.properties” file (mapping ruleName to ruleClass). But that is kind of brute force, and certainly violates DRY. I think that ruleset capability would be valuable, and I would be inclined to recommend that as the “right” way for users to build their own custom rulesets, rather than assembling rulesets from our existing rulesets (e.g. basic, concurrency, etc.). That would remove the dependency on specific ruleset files, containing a set of rules that changes from release to release. That dependency on changing ruleset files causes me some hassle migrating 15+ projects with every release of CodeNarc, so I assume some other users experience that pain as well. And, whether they use Grails or Gradle or just Ant, I think that most users end up customizing their rulesets. I also wonder whether having a single, definitive list/repository of all rules might benefit tools like the IDEA plugin or a future “CodeNarc Configuration Console”. But what do you think? Chris From: chr...@wa... [mailto:chr...@wa...] Sent: Monday, January 24, 2011 9:34 AM To: Hamlet DArcy Cc: cod...@li... Subject: Re: [Codenarc-user] CodeNarc rulesets - even necessary? But even using Gradle/Grails/Griffon plugins, you often still need to assemble a custom ruleset. I may still explore options such as @Rule and configuring a custom ruleset without needing to reference those individual predefined rulesets. I think that could be done without harming backwards-compatibility. Chris Hamlet DArcy <ham...@ca...> wrote on 01/24/2011 03:23:00 AM: > To me, the future lies in tools like the Grails, Griffon, Gradle, > and IDEA plugins. There are few questions (so far) about how to use > CodeNarc with these tools because the plugins take care of it for you. > > I wouldn't make any changes now because of backwards compatibility. > > -- > Hamlet D'Arcy > ham...@ca... > > ----- Original Message ----- > > Okay, to continue the discussion about the necessity of rulesets... > > > > > > > > >> But why even have rulesets? ... > > > > > > > > In general, I agree with you. Although we have done a little bit of > > mix-and-match of picking rulesets at my work (e.g. pulling in the > > Grails rules only for Grails projects), overall that has probably not > > been worth the effort and complexity of maintaining those separate > > rulesets. > > > > > > > > But I would add that having something like the "Basic" ruleset is > > valuable -- here are a "minimal" set of rules that pretty much > > everyone can agree on. This is often the way to wade into using a tool > > like CodeNarc. (Though I admittedly let the "basic" ruleset drift away > > from that core mission a bit) > > > > > > > > At this point, for backward-compatibility, I don' think we could just > > remove the existing rulesets. > > > > > > > > That all being said, I do think there is definitely room for > > reorganization, improvement and innovation. > > > > > > > > We could create one "All-Rules" ruleset. The Groovy Ruleset DSL could > > be used as-is, but we’d have to figure out some scheme to NOT > > automatically include all the rules in the ruleset by default, as it > > does today, e.g. > > > > > > > > ruleset { > > > > ruleset('rulesets/all-codenarc-rules.xml', excludeByDefault:true ) { > > > > CatchThrowable(priority:1) // only include explicitly-configured rules > > > > EqualsAndHashCode(priority:3) > > > > ThrowExceptionFromFinallyBlock() > > > > UnnecessaryConstructor() > > > > } > > > > } > > > > > > > > Another option along these lines is to automatically retain a > > "registry" of all rules, indexed by name. Perhaps we could introduce a > > @Rule (or somesuch) annotation for the rule implementations. I had > > considered that from the beginning, but back then I needed to maintain > > compatibility with Java 1.4 (don't get me started), so I could not > > support annotations. I think it would then be possible to extend the > > Groovy Ruleset DSL to automatically look into this registry for rule > > names, so, there would be no need to specify an explicit ruleset file, > > e.g. > > > > > > > > ruleset { > > > > CatchThrowable(priority:1) > > > > EqualsAndHashCode(priority:3) > > > > MethodCount { > > > > doNotApplyToClassNames = ‘*Test, *TestCase’ > > > > } > > > > UnnecessaryConstructor() > > > > } > > > > > > > > That seems quite nice and usable from my perspective. > > > > > > > > > > > > >> One idea I had for simplification was to provide a "CodeNarc > > >> Configuration Console"... > > > > > > > > That sounds pretty cool. > > > > > > > > Chris > > > > -----Original Message----- > > From: Hamlet DArcy [mailto:ham...@ca...] > > Sent: Friday, January 21, 2011 9:31 AM > > To: chris mair > > Cc: cod...@li...; Jason Stell > > Subject: Re: [Codenarc-user] Ruleset Resources Namespace Conflict > > > > > > > > This is getting off topic from Jason's email... > > > > > > > > But why even have rulesets? You can't actually make a decision based > > on rulesets. You never say "you know, I want the concurrency ruleset > > but not the exception ruleset". You would always look inside the set > > and make decisions about individual rules. In my mind, I'd rather see > > two and only two rulesets: CodeNarc rules and user rules. > > > > > > > > One idea I had for simplification was to provide a "CodeNarc > > Configuration Console". It would read the ruleset.xml files and > > produce a tree view UI based on the rule classes, the declared > > parameters, and the documentation. Then the user could just click > > checkboxes and text fields until they had the configuration they > > wanted and export the correct codenarc-properties.groovy file. The > > model would be the IntelliJ IDEA Inspections UI. It's a bit of work > > but nothing too challenging. A Gaelyk app would be cool. Can't we talk > > someone from Gaelyk into doing this? I wonder what rentacoder.com > > would charge. > > > > > > > > > > > > -- > > > > Hamlet D'Arcy > > > > ham...@ca... > > > > > > > > ----- Original Message ----- > > > > > Yes, in hindsight, I should have put the ruleset files in a unique > > > > > namespace, and as Hamlet suggested, avoiding specific rulesets > > > > > altogether might have been a better approach. > > > > > > > > > > Is there anything forcing you to use the same classpath for both > > > > > CodeNarc and PMD? > > > > > > > > > > I don't think we can, at this point, move the CodeNarc ruleset > > > files, > > > > > since that would break every user. Copying the ruleset files to a > > > > > different location may help as a workaround, but I don't think that > > > > > would solve the problem if the CodeNarc files are "hiding" the > > > > > CodeNarc ones. > > > > > > > > > > Chris > > > > > > > > > > > > > > > Hamlet DArcy < ham...@ca... > > > > > > > > > > > 01/21/2011 09:05 AM > > > > > > > > > > To Jason Stell < js...@gm... > > > > > > > > > > > cc cod...@li... > > > > > > > > > > Subject Re: [Codenarc-user] Ruleset Resources Namespace Conflict > > > > > > > > > > > > > > > > > > > > > > > > > CodeNarc is modeled on PMD so we have all those ruleset files in > > > > > common. Personally, I find both projects a little difficult to > > > > > configure. I'd prefer to see one massive configuration file. But > > > > > that's water under the bridge at this point. As you know, there is > > > > > nothing special about that location. You /can/ copy all the contents > > > > > of the ruleset xml files and dump them into one big file. > > > > > > > > > > -- > > > > > Hamlet D'Arcy > > > > > ham...@ca... > > > > > > > > > > ----- Original Message ----- > > > > > > It does kinda stink ;) I would have suggested a change to PMD > > > > > > resource names, as well, but that project has been around a long > > > > > > time and a change would probably impact many more users (still, as > > > > a > > > > > > good practice, they should also think about putting resources in > > > > an > > > > > > appropriate namespace). > > > > > > > > > > > > > > > > > > As a workaround I can always extract/copy the rulesets I'm using > > > > and > > > > > > put them in a different local namespace. > > > > > > > > > > > > > > > > > > Oh - and thanks for CodeNarc! > > > > > > > > > > > > > > > > > > Regards > > > > > > Jason > > > > > > > > > > > > > > > > > > On Fri, Jan 21, 2011 at 1:30 AM, Hamlet DArcy < > > > > > > ham...@ca... > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > If I have both CodeNarc and PMD libs in my classpath, I have > > > > > > > problems > > > > > > > > > > > > Well that stinks. If we rename the rules then we have backwards > > > > > > compatibility issues. :( We'll have to discuss what to do. > > > > > > > > > > > > Do you need a workaround temporarily? Or do you have that covered? > > > > > > > > > > > > > > > > > > -- > > > > > > Hamlet D'Arcy > > > > > > ham...@ca... > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ----- Original Message ----- > > > > > > > If I have both CodeNarc and PMD libs in my classpath, I have > > > > > > > problems with one or the other, because both have resources with > > > > > > > the same > > > > > > > name: > > > > > > > e.g., 'rulesets/basic.xml', 'rulesets/design.xml', etc. How > > > > > about > > > > > > > using a safer resource namespace, like > > > > > > > 'org/codenarc/rulesets/...'? > > > > > > > > > > > > > > > > > > > > > Thanks! > > > > > > > Jason > > > > > > > ------------------------------------------------------------------ > > > > > > > ------------ Special Offer-- Download ArcSight Logger for FREE > > > > > (a > > > > > > > $49 USD value)! > > > > > > > Finally, a world-class log management solution at an even better > > > > > > > price-free! > > > > > > > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > > > > > > > February 28th, so secure your free ArcSight Logger TODAY! > > > > > > > http://p.sf.net/sfu/arcsight-sfd2d > > > > > > > _______________________________________________ > > > > > > > Codenarc-user mailing list > > > > > > > Cod...@li... > > > > > > > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > > > > > > > > > ---------------------------------------------------------------------- > > > > > -------- Special Offer-- Download ArcSight Logger for FREE (a $49 > > > USD > > > > > value)! > > > > > Finally, a world-class log management solution at an even better > > > > > price-free! > > > > > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > > > > > February 28th, so secure your free ArcSight Logger TODAY! > > > > > http://p.sf.net/sfu/arcsight-sfd2d > > > > > _______________________________________________ > > > > > Codenarc-user mailing list > > > > > Cod...@li... > > > > > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > > > > > > > > > ForwardSourceID:NT000F67C6 > > > > > > > > > ------------------------------------------------------------------------------ > > > > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > > > > Finally, a world-class log management solution at an even better > > price-free! > > > > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > > February 28th, so secure your free ArcSight Logger TODAY! > > > > http://p.sf.net/sfu/arcsight-sfd2d > > > > _______________________________________________ > > > > Codenarc-user mailing list > > > > Cod...@li... > > > > https://lists.sourceforge.net/lists/listinfo/codenarc-user > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > Codenarc-user mailing list > Cod...@li... > https://lists.sourceforge.net/lists/listinfo/codenarc-user > ForwardSourceID:NT000F9A3A |