def define_rule(rule_type, name, **kwargs):
    """Generate a string representing a rule definition.

    Take care to escape string values using repr().

    ### Examples

      ```bzl
      define_rule("myrule",
          name = "foo",
          myattr1 = repr("bar"),
          myattr2 = ["baz"],
      )
      ```
    """
    attrs = ["{} = {},".format(k, v) for k, v in kwargs.items() if v != None]
    skeleton = """\
{rule_type}(
    name = {name},
    {attrs}
)
"""
    return skeleton.format(
        rule_type = rule_type,
        name = repr(name),
        attrs = "\n    ".join(attrs),
    )