Created
January 30, 2020 11:57
-
-
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
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
#!/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