From 56702d74f718691b18827c50779eb38fc529cab2 Mon Sep 17 00:00:00 2001 From: MorganGeek Date: Mon, 13 Jul 2020 16:19:08 +0200 Subject: [PATCH] helper to list invalid filenames in manuals/readme - Helper name is `invalid_file_refs` and can be used like this : `invalid_file_refs README.*` - Given a document (readme, manual...) containing file names, the script will attempt to identify what file names are either not referenced in the source code, or missing in the project, thus helping to detect some potentials issues. - Example of issue detected by this tool : the README.md mentions a `config.yaml` while the application would search for `config.yml`. Because of this mistake, the user might struggle to make the application work. --- dot_zsh_functions | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dot_zsh_functions b/dot_zsh_functions index 832132f..0049656 100644 --- a/dot_zsh_functions +++ b/dot_zsh_functions @@ -209,6 +209,34 @@ function how_in() { shift IFS=+ curl "cht.sh/${where}/$*" } +# File name references in file +function filerefs() { + \grep -Eo "\b([a-zA-Z.]+)\.([a-z]{2,4}\b)" "$1" \ + | sort -u \ + | egrep -vi "\.com|\.git|\.io|\net|\.org|\.se|\.me|\.fr|contributing\.md" +} +function invalid_file_refs() { + while read -r file_ref; do + arrow "processing $file_ref ..." + find . -name "$file_ref" 1>/dev/null + local exit_status=$? + if [ $exit_status -eq 1 ]; then + warning "$file_ref does not exist in the project" + else + success "$file_ref was found in the project" + fi + arrow "checking if $file_ref is present in the source code..." + source_refs=$(\grep "$file_ref" * -r -l | grep -v "$1" | wc -l 2>/dev/null | trim) + if [ "$source_refs" -eq 0 ]; then + error "$file_ref was not found in source code" + else + arrow "searching for $file_ref references in soure code..." + while read -r source_ref; do + success "$file_ref was found in $source_ref" + done < <(\grep "$file_ref" * -r -l) + fi + done < <(filerefs "$1") +} # File stats helpers # Find files bigger than X size and sort them by size