codegram/pelusa — pull request #33 by arsduo (2012-11-17 01:18:47+00:00)
Title: Add options to DemeterLaw

I've started using Pelusa as a linter running as part of my test suite for non-Rails gems. I'm really liking it so far; it's a great alternative to RailsBP for projects that can't use the former.

As you acknowledge in the documentation, though, the defaults here aren't a perfect match to how people may want to code, so I've started adding options to the various filters.

To start with, for Demeter's law, here are two new flags:

* Add a `whitelist` option, which takes a comma-separated list of Classes to serve as whitelist sources. My use case (likely a common one) is to allow Hash or Array methods (or whatever else) to be used without raising Demeter warnings.
* Add an `allow_conversions` option, which further allows methods matching /^(to_|as_)/ to pass. For instance, user.shares.as_json, or object.method.to_time.

In both cases, I think the value of allowing the violation (in terms of clean and readable code) outweigh the harm done. Purists could configure it differently (setting whitelist: "" would disable all exceptions).

What do you think?