Last active
December 14, 2016 08:57
-
-
Save mreschke/a0171246f31cc1d7fc09946a58bcfba9 to your computer and use it in GitHub Desktop.
Convert to PSR-2 and Tabs to Spaces
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
#!/bin/bash | |
# Convert tabs to spaces in code files | |
# and convert all PHP files (that begin with <? or <?php, so not laravel blade files) to PSR-2 | |
# Requires https://github.com/FriendsOfPHP/PHP-CS-Fixer in $path | |
# mReschke 2016-09-28 | |
dir=$(pwd) | |
# Replace tabs with 4 spaces in particular files | |
# First find section ignores folders | |
# Second find section includes files | |
# Third find section ignores files | |
echo "Converting spaces to tabs in most code files" | |
find . \ | |
\( \ | |
-path ./node_modules -prune \ | |
-o -path ./.git -prune \ | |
-o -path ./.svn -prune \ | |
-o -path ./vendor -prune \ | |
-o -path ./storage -prune \ | |
-o -type f \) \ | |
\( \ | |
-iname "*.php" \ | |
-o -iname "*.js" \ | |
-o -iname ".css" \ | |
-o -iname ".txt" \ | |
-o -iname "*.md" \ | |
-o -iname "*.json" \ | |
-o -iname "*.xml" \ | |
-o -iname "*.yml" \ | |
\) \ | |
\( ! -iname "*.min.js" \) \ | |
| xargs sed -i -e 's/\t/ /g' | |
# Convert to PSR-2 | |
echo "Converting PHP files to PSR-2" | |
find . \( \ | |
-path ./vendor -prune \ | |
-o -path ./.git -prune \ | |
-o -path ./.svn -prune \ | |
-o -path ./storage -prune \ | |
-o -type f \) \ | |
-iname "*.php" \ | |
-exec php-cs-fixer fix {} --level=psr2 \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment