def fix_white_space(): info('Fixing whitespace errors...') return local("git ls-files -z | " "grep -PZvz '\.(ico|jpg|png|gif|eot|ttf|woff|wav|xlxs)$' | " "xargs -0 grep -PlZn '(\\s+$)|(\\t)' | " "tee /dev/stderr | " "xargs -0 -r sed -i -e 's/\\s\\+$//' ")
def python_code_analyzer(): """Running static code analyzer""" info('Running static code analyzer') return local("git ls-files -z | " "grep -PZz '\.py$' | " "grep -PZvz 'fabfile.py' | " "xargs -0 pyflakes")
def find_php_syntax_errors(): """Find syntax error in php files """ info('Finding syntax error in php files...') return local("git ls-files -z | " "grep -PZz '\.(php|phtml)$' | " "xargs -0 -n 1 php -l >/tmp/debug")
def convert_tab_spaces(): info('Converting tab to spaces...') return local("git ls-files -z | " "grep -PZvz '\.(ico|jpg|png|gif|eot|ttf|woff|wav|xlxs)$' | " "xargs -0 grep -PlZn '(\\s+$)|(\\t)' | " "tee /dev/stderr | " "xargs -0 -r sed -i -e 's/\\t/ /g' ")
def check_image_edited(): # Check if image files have been edited info('Checking if image files have been edited...') info('Explanation: A new image should be created when ' 'editing images to avoid browser caching') branch = local('git rev-parse --abbrev-ref HEAD') return local('! git diff master...' + branch + ' --name-only --diff-filter=M | ' + 'grep ".gif\|.png\|.jpg"')
def check_python_debug_info(): """Check and remove debugging print statements""" info('Checking for debug print statements') return local("! git ls-files -z | " "grep -PZvz 'fabfile.py' | " "grep -PZz \.py$ | " "xargs -0 grep -Pn \'(?<![Bb]lue|>>> )print\' | " "grep -v NOCHECK")
def code_analyzer(): """Running static code analyzer""" info('Running static code analyzer...') return local("git ls-files -z | " "grep -vz '^\.' | " "grep -Pvz '\.(md|yml|log|txt|lock)$' |" "grep -Pzv '(fabfile.py|Makefile)' |" "grep -Pzv '(sample|cron)' |" "xargs -0 pyflakes")
def run_pyflakes(): """ Run pyflakes """ info('Running static code analysis...') return local("git ls-files | " "awk '/^healthscoop\/.*\.py$/ {print $1}' | " "awk '!/^healthscoop\/manage/' | " "xargs pyflakes")
def check_pep8_styles(): """ Run pep8 python coding standard check """ info('Running style check...') return local("git ls-files | " "awk '/^healthscoop\/.*\.py$/ {print $1}' | " "awk '!/^healthscoop\/manage/' | " "xargs pycodestyle --config=conf/pycodestyle")
def remove_debug_info(): """Check and remove debugging print statements""" # Have to remove scripts and test file info('Checking for debug print statements...') return local("! git ls-files -z | " "grep -PZvz '^scripts/' | " "grep -PZvz 'tests/run_tests.py' | " "grep -PZvz 'fabfile.py' | " "grep -PZz \.py$ | " "xargs -0 grep -Pn \'(?<![Bb]lue|>>> )print\' | " "grep -v NOCHECK")
def remove_compiled_classes(): # Remove compiled python classes info('Removing compiled python classes...') return local("find ./ -name '*.py[co]' -print0 | xargs -0 rm -f")
def find_merge_conflict_leftovers(): """ Avoid merge conflicts """ info('Finding merge conflict leftovers...') return local("! git grep -P '^(<|=|>){7}(?![<=>])'")
def run_test(): info('Running tests...') return local('nose2 --config conf/nose2.cfg')
def check_preg_replace(): info('Checking use of preg_replace...') return local("! find src -name '*.php' -print0 | " "xargs -0 grep -n 'preg_replace('")
def check_migration_branch(): """Checking migration branches""" info('Checking migration branches...') return local("! alembic branches | grep branchpoint")
def composer_validate(): info('Running composer validate...') return local('composer validate')
def run_eslint(): info('Running ESLint...') return local("git ls-files | " "grep '\.js$' | " "xargs ./node_modules/eslint/bin/eslint.js")
def fix_script_permission(): # Fix script permissions info('Fixing script permissions...') return local("git ls-files -z | " "grep -PZz '\.sh$' | " "xargs -0 -r chmod 0775 >/dev/null 2>&1")
def fix_file_permission(): """Fixing permissions for files""" info('Fixing permissions for files') return local("git ls-files -z | " "grep -PvZz '\.sh$' | " "xargs -0 chmod -c 0664 > /dev/null 2>&1")
def find_pep8_violations(): """Run pep8 python coding standard check """ info('Running coding standards check for python files...') return local("git ls-files -z | " "grep -PZz '\.py$' | " "xargs -0 pep8")
def check_php_debug_info(): info('Checking for var_dump, echo or die statements...') return local("! find ./src -name '*.php' -print0 | " "xargs -0 egrep -n 'var_dump|echo|die' | grep -v 'NOCHECK'")
def composer_security_check_npm(): """Requires nsp in package""" info('Running security check for python dependencies...') return local("safety check -r requirements.txt")
def check_python_code_complexity(): info('Checking code complexity...') return local("xenon fabpolish -bB -mA -aA")