Skip to content

Instantly share code, notes, and snippets.

@mbaranowski
Created July 20, 2018 18:24
Show Gist options
  • Save mbaranowski/1911dd6ec8bda8cedd2fba385d3d2db9 to your computer and use it in GitHub Desktop.
Save mbaranowski/1911dd6ec8bda8cedd2fba385d3d2db9 to your computer and use it in GitHub Desktop.
SourceKitten Class Inheritance JQ script
# run with
# jq -S -f sourcekitten_class_inheritance.jq sourcekitten_doc_output.json > output.json
def splitDotLast: split(".") | .[-1];
def isClassOrExtension(kind):
kind == "class" or kind == "extension" or kind == "protocol";
def isSelected:
isClassOrExtension(.["key.kind"] | splitDotLast)
and
(."key.name" | endswith("ViewController"));
def removeWhitespace: gsub("\\s+";"");
[
.. | select( isSelected )? # recursive walk to pick out all sourcekit objects matching criteria
| {
"name":."key.name",
"kind": ."key.kind" | splitDotLast,
"inherits": [."key.inheritedtypes" | .[]."key.name" | removeWhitespace ]
}
]
# combine class/extension/protocol declaration based on name
| group_by(.name)
| map({"name": .[0].name,
#"kind": map(.kind) | unique,
"inherits": (map(.inherits) | add) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment