function analyze(rule, local) {
  /** @type {Set<string>} */
  const defined = new Set()
  /** @type {Set<string>} */
  const referenced = new Set()

  visit(
    rule,
    /** @returns {undefined} */
    function (rule) {
      if ('repository' in rule && rule.repository) {
        for (const key of Object.keys(rule.repository)) {
          defined.add(key)
        }
      }

      if (
        'include' in rule &&
        rule.include &&
        (!local || rule.include.startsWith('#'))
      ) {
        referenced.add(rule.include)
      }
    }
  )

  return {defined, referenced}
}
@param {Rule} rule
  Rule to analyze.
@param {boolean | null | undefined} [local=false]
  Whether to include only local references (default: `false`).
@returns {{defined: Set<string>, referenced: Set<string>}}
  Info about the rule.