squabble.rule module

squabble.rule.load_rules(plugin_paths=None)[source]

Load built in rules as well as any custom rules contained in the directories in plugin_paths.

squabble.rule.node_visitor(fn)[source]

Helper decorator to make it easier to register callbacks for AST nodes. Effectively creates the partial function automatically so there’s no need for a lambda.

Wraps fn to pass in self, context, and node when the callback is called.

>>> from squabble.rules import BaseRule
>>> class SomeRule(BaseRule):
...     def enable(self, ctx, config):
...         # These are equivalent
...         ctx.register('foo', self.check_foo(x=1))
...         ctx.register('bar', lambda c, n: self.check_bar(c, n, x=1))
...
...     @node_visitor
...     def check_foo(self, context, node, x):
...         pass
...
...     def check_bar(self, context, node, x):
...         pass
class squabble.rule.Registry[source]

Bases: object

Singleton instance used to keep track of all rules.

Any class that inherits from squabble.rules.BaseRule will automatically be registered to the registry.

static register(rule)[source]
static get_meta(name)[source]

Return metadata about a given rule in the registry.

If no rule exists in the registry named name, UnknownRuleException will be thrown.

The returned dictionary will look something like this:

{
    'name': 'RuleClass',
    'help': 'Some rule...',
    # ...
}
static get_class(name)[source]

Return class for given rule name in the registry.

If no rule exists in the registry named name, UnknownRuleException will be thrown.

static all()[source]

Return an iterator over all known rule metadata. Equivalent to calling get_meta() for all registered rules.