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
fnto pass inself,context, andnodewhen 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:
objectSingleton instance used to keep track of all rules.
Any class that inherits from
squabble.rules.BaseRulewill automatically be registered to the registry.-
static
get_meta(name)[source]¶ Return metadata about a given rule in the registry.
If no rule exists in the registry named
name,UnknownRuleExceptionwill 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,UnknownRuleExceptionwill be thrown.
-
static
all()[source]¶ Return an iterator over all known rule metadata. Equivalent to calling
get_meta()for all registered rules.
-
static