diff --git a/test/sanity/code-smell/empty-init.json b/test/sanity/code-smell/empty-init.json new file mode 100644 index 0000000000..43d0bd3501 --- /dev/null +++ b/test/sanity/code-smell/empty-init.json @@ -0,0 +1,11 @@ +{ + "prefixes": [ + "lib/ansible/modules/", + "lib/ansible/module_utils/", + "test/units/" + ], + "extensions": [ + ".py" + ], + "output": "path-message" +} diff --git a/test/sanity/code-smell/empty-init.py b/test/sanity/code-smell/empty-init.py new file mode 100755 index 0000000000..f55817dc67 --- /dev/null +++ b/test/sanity/code-smell/empty-init.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import os +import re +import sys + + +def main(): + skip = set([ + 'test/sanity/code-smell/%s' % os.path.basename(__file__), + # facts is grandfathered in but will break namespacing + # the only way to fix it is to deprecate and eventually remove it + # six will break namespacing but because it is bundled we should not be overriding it + 'lib/ansible/module_utils/facts/__init__.py', + 'lib/ansible/module_utils/six/__init__.py', + ]) + + for path in sys.argv[1:]: + if path in skip: + continue + + if os.path.basename(path) != '__init__.py': + continue + + if os.path.getsize(path) > 0: + print('%s: empty __init__.py required' % path) + + +if __name__ == '__main__': + main() diff --git a/test/sanity/code-smell/empty-init.sh b/test/sanity/code-smell/empty-init.sh deleted file mode 100755 index 3ae810f5f9..0000000000 --- a/test/sanity/code-smell/empty-init.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -found='' - -for path in lib/ansible/modules/ lib/ansible/module_utils test/units/; do - # facts is grandfathered in but will break namespacing. Only way to fix it - # is to deprecate and eventually remove. - # six will break namespacing but because it is bundled we should not be overriding it - files=$(find "${path}" -name __init__.py -size '+0' | sed '\!lib/ansible/module_utils/\(six\|facts\)/__init__.py!d') - - if [ "${files}" ]; then - echo "${files}" - found=1 - fi -done - -if [ "${found}" ]; then - echo "One or more __init__.py file(s) listed above are non-empty." - exit 1 -fi diff --git a/test/sanity/code-smell/inappropriately-private.sh b/test/sanity/code-smell/inappropriately-private.sh deleted file mode 100755 index 9ee3342179..0000000000 --- a/test/sanity/code-smell/inappropriately-private.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# -# Test that we do not access private attributes of other objects. -# -# * private attributes of ourself are okay: self._private. -# * Private attributes of other objects are not: self.other._private -# - -# Currently the code has many places where we're violating this test so we need -# to clean up the code before we can enable this. Maybe we'll need to -# selectively blacklist modules so that we can work on this a piece at a time. -# -# Also need to implement whitelist for certain things like bundled libraries -# that violate this. -# -# 23-10-2015: Count was 508 lines -grep -Pri '(?