Skip to content

Commit

Permalink
Merge pull request #1 from practo/add_sniffs
Browse files Browse the repository at this point in the history
adding common sniffs
  • Loading branch information
amankrbl committed Apr 26, 2016
2 parents 2a4c178 + 4cb6b07 commit 69f6362
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions fabpolish/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ def find_php_syntax_errors():
)


@sniff(severity='major', timing='fast')
def 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"
)


@sniff(severity='minor', timing='slow')
def find_pep8_violations():
"""Run pep8 python coding standard check
Expand All @@ -31,3 +43,89 @@ def find_pep8_violations():
"grep -PZz '\.py$' | "
"xargs -0 pep8"
)


@sniff(severity='major', timing='fast')
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"
)


@sniff(severity='major', timing='fast')
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"
)


@sniff(severity='major', timing='fast')
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\\+$//' "
)


@sniff(severity='major', timing='fast')
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' "
)


@sniff(severity='critical', timing='fast')
def check_migration_branch():
"""Checking migration branches"""
info('Checking migration branches...')
return local("! alembic branches | grep branchpoint")


@sniff(severity='major', timing='fast')
def remove_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"
)


@sniff(severity='major', timing='fast')
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"'
)


@sniff(severity='critical', timing='fast')
def composer_validate():
info('Running composer validate...')
return local('composer validate')

0 comments on commit 69f6362

Please sign in to comment.