| #!/bin/bash | |
| # Detect trivial unused code. | |
| # | |
| # Automatically removal is possible, but is considered an unsafe operation. When a | |
| # change hasn't been commited, automatic removal could cause unintended irreversible | |
| # loss of in-progress code. | |
| # | |
| # Note: This cannot detect unused code between modules or packages. For complex unused | |
| # code detection, vulture should be used. | |
| autoflake \ | |
| --quiet \ | |
| --check-diff \ | |
| --remove-duplicate-keys \ | |
| --remove-unused-variables \ | |
| --remove-all-unused-imports \ | |
| --recursive . | |
| if [ $? -eq 0 ]; then | |
| echo "No unused code found" | |
| else | |
| echo "" | |
| echo "=======================================================" | |
| echo "Unused code detected! Please fix then rerun this script" | |
| echo "=======================================================" | |
| echo "" | |
| echo "If these changes are trivial, consider running:" | |
| echo "\"autoflake --in-place --remove-unused-variables --remove-all-unused-imports -r .\"" | |
| exit 1 | |
| fi | |
| # Sort imports to avoid bikeshedding. | |
| isort . | |
| # Format code; also to avoid bikeshedding. | |
| black . | |