-
Notifications
You must be signed in to change notification settings - Fork 153
rules in code? #8
Comments
Hi KC, I think from your description this has more to do with how foodcritic requires its own libraries. I've tweaked this - can you pull from master and you should see changes reflected without a build: Cheers, Andrew. |
Or were you saying you'd like an option to define site-specific cookbook rules in config external to the gem? |
Yes, that's what I meant. I suspect the defaults that come with the gem should continue to reflect what the community thinks should be the standards. Rather than making people fork and rebuild the gem to add their own organizational standards which may not be suitable for the larger community, which they then have to maintain, why not just allow a config file/dir where you can add in custom rulesets independent of the gem? And maybe disable defaults as well so you don't have to pass it on the command line. |
Hi KC, Are you able to give specific examples of rules that you think people may want to apply that it would not make sense to contribute back? I'd think I prefer instead to encourage contributions back and have a set of 'default' rules that are normally run. Users can then choose to apply more specialised rules (outside the default set but included with the gem) if it is appropriate for their situation. Assuming other users may share your itch then this should prevent duplication of effort (everyone gets to benefit from your custom rule) and ensures that changes in the API that cause breakage will be picked up. Does this work for you? |
I expect some companies will want things that no one else would but I'll close this until I have specific examples. |
I have plenty of examples. I may want people to not use search (for scalability reasons) in cookbooks. there's a BILLION reasons this is a good idea and I was going to request the same thing until I saw it was already here. |
Re-opening this issue at jaymzh's request. |
As a side-note, the way I'd sorta see this being implemented is a config entry that defines a site-specific library directory and a list of rules to load (the same way there's a list of built-in ones in the code). At run-time you'd walk that list and load them the same way (I don't know crap about cucumber, so I don't know how easy/hard it is to do that). |
Ok, I'm convinced it would be useful :-) Versioning I've had specs for the rule API on my todo list for a while, so this is extra impetus to get this done so I won't break your stuff inadvertently on minor releases. I can't responsibly ship this feature without these specs being in place. Implementation Cheers, Andrew. |
The implementation sounds good. Would you load every rule in that directory? What if there was a README, would you croak? For versioning... I don't know enough about ruby (yet). Ideally there'd be something like so-versions that we have in c libraries... or perhaps that way mozilla does plugin versioning where the rules say what version they believe they work on? |
The Ruby way is just to If I make a Category 3 change to the rules API which I expect to break your existing code then I would bump the Foodcritic major version. Normally you would express compatibility through gem constraints - you might choose the wonderfully named sperm operator: This assumes a slightly different model then what we've said above, where you would create a Need to give it some more thought. |
Yeah building gem files is pretty heavy-weight. I'm fine with saying API changes mean a major version bump. Also, <3 the sperm operator. |
Hi guys, This feature is in 1.0.0 - please give it a try and let me know how you get on. It still needs API documentation but you should be able to get started. This existing section of the docs relates more to modifying the existing codebase but may still be helpful: # my_custom_rule.rb
rule "MYORG001", "My custom rule" do
tags %w{style attributes}
recipe do |ast|
attribute_access(ast, :type => :string).map{|ar| match(ar)}
end
end
|
Andrew, Thanks for this! As you mentioned, there's not really docs here, so I'm going to ask a few questions. First, I couldn't get pry to dump the API:
Second, I tried to use the example above to match all gem_package with like:
But it crashes:
|
Hi Phil, You want to be in the context of a rule, so declare one first. When you type
Now you can list the available methods and ask Pry to show you the documentation. The rule will be invoked for each recipe file - use
Hope this helps. Cheers, Andrew. |
Oh, that's awesome, thanks! Is it possible to specify or-able requirements? I tried:
but neither worked. I can obviously make two rules... but it seemed like a useful thing to do. (chef_gem is coming in 0.10.10) |
You can't pass an array of types to You can achieve the same effect by calling find_resources(ast).find_all do |res|
%w{gem_package chef_gem}.include?(resource_type(res))
end.map{|pkg| match(pkg)} |
Awesome. Foodcritic is seriously going save me so much pain and effort. Thanks so much for knocking out so many RFEs so quickly! |
BTW, I'm now using this in production. It is awesome. |
Thanks! I'm expecting to make some progress on the documentation this week. |
- Moved to Jekyll and Bootstrap 2 - API docs added
I guess this is more of a feature request, but does it make sense for the rules to be in the code of the app rather than a configuration? It seems wrong to have to rebuild the application to add new rules.
The text was updated successfully, but these errors were encountered: