Created
July 20, 2018 18:24
-
-
Save mbaranowski/1911dd6ec8bda8cedd2fba385d3d2db9 to your computer and use it in GitHub Desktop.
SourceKitten Class Inheritance JQ script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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