Skip to content

Instantly share code, notes, and snippets.

@pspi
Created January 30, 2020 11:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pspi/a064fdef9c18cb1cfb24b453c09313d1 to your computer and use it in GitHub Desktop.
Save pspi/a064fdef9c18cb1cfb24b453c09313d1 to your computer and use it in GitHub Desktop.
Calculate ratio of single quotes to double quotes in .js and .ts files
#!/usr/bin/env bash
# TODO:
# - DRY relevant parts
singlequotes=`find -type f \( -iname \*.js -o -iname \*.ts \) -not -path '*node_modules/*' -exec cat \{\} \; | tr -cd \' | wc -c`
doublequotes=`find -type f \( -iname \*.js -o -iname \*.ts \) -not -path '*node_modules/*' -exec cat \{\} \; | tr -cd '"' | wc -c`
total=$(($singlequotes + $doublequotes))
singlequotespercentage=`node -pe "Math.round($singlequotes / $total * 100)"`
doublequotespercentage=`node -pe "Math.round($doublequotes / $total * 100)"`
basename `pwd`
if [ $singlequotes -gt $doublequotes ] ; then
echo "Single quotes (') are more dominant: $singlequotespercentage %"
else
echo "Double quotes (\") are more dominant: $doublequotespercentage %"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment