Skip to content

Instantly share code, notes, and snippets.

@gwillcox-r7
Last active November 10, 2022 06:44
Show Gist options
  • Save gwillcox-r7/b82047483b106cf7f2c11094ed04cc16 to your computer and use it in GitHub Desktop.
Save gwillcox-r7/b82047483b106cf7f2c11094ed04cc16 to your computer and use it in GitHub Desktop.
YARD Missing Documentation Generator
#!/bin/bash
# Generate the raw YARD stats on undocumented
yard stats -q --list-undoc --compact > undocumented-api.txt
# Strip out the statistics at the top of the output. For some reason --no-stats doesn't seem to stop this being printed.
pcregrep -Mv "[\w\W]+Undocumented Objects:" undocumented-api.txt > filtered1-undocumented-api.txt
# Turn the file names into links to the equivalent GitHub Pages
sed 's/(/https:\/\/github\.com\/rapid7\/metasploit-framework\/blob\/master\//' filtered1-undocumented-api.txt > filtered2-undocumented-api.txt
# Replace the line numbers with GitHub's formatting for line numbers.
sed -r 's/:([[:digit:]]+)\)/#L\1/' filtered2-undocumented-api.txt > filtered3-undocumented-api.txt # Taken from https://stackoverflow.com/a/4020038
# Replace whitespace with --- to make it easier to work with the file.
sed -r 's/\s+/---/' filtered3-undocumented-api.txt > filtered4-undocumented-api.txt
# Replace beginning of the file with `- [ ] [` to start a link based checklist.
sed -r 's/^/- [ ] [/' filtered4-undocumented-api.txt > filtered5-undocumented-api.txt
# Replace the --- from earlier with the closing part of the link syntax and then start the link contents inside ().
sed -r 's/---/](/' filtered5-undocumented-api.txt > filtered6-undocumented-api.txt
# Finally add the terminating ) to the end of each line to get it to render the link properly.
sed -r 's/$/)/' filtered6-undocumented-api.txt > filtered-undocumented-api.md
# Echo out the contents of the final file
echo 'Open up filtered-undocumented-api.md to view final contents!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment