Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show latest pre-commit hook dependencies.
#!/bin/bash
#
# Script to show list of dependencies for pre-commit hook.
#
# Requirements
# ============
#
# - [curl](https://curl.haxx.se/)
# - [jq](https://stedolan.github.io/jq/)
# - [npm](https://www.npmjs.com/)
#
# Usage
# =====
#
# ```bash
# show-hook-dependencies.sh HOOK
# ```
#
# List of supported hooks
# =======================
#
# - flake8
# - eslint
#
set -e
FLAKE8_DEPENDENCIES="
flake8
flake8-broken-line
flake8-bugbear
flake8-builtins
flake8-comprehensions
flake8-eradicate
flake8-import-order
flake8-mutable
flake8-pie
flake8-quotes
flake8-string-format
flake8-tidy-imports
pep8-naming
"
ESLINT_DEPENDENCIES="
babel-eslint
eslint
eslint-config-prettier
eslint-config-standard
eslint-plugin-import
eslint-plugin-node
eslint-plugin-prettier
eslint-plugin-promise
eslint-plugin-react
eslint-plugin-react-hooks
eslint-plugin-standard
prettier
"
function get_js_package_version() {
npm view ${1} version
}
function get_python_project_version() {
curl -s "https://pypi.org/pypi/${1}/json" | jq -r ".info.version"
}
function show_flake8_dependencies() {
for project in ${FLAKE8_DEPENDENCIES}; do
echo " - ${project}==$(get_python_project_version ${project})"
done
}
function show_eslint_dependencies() {
for package in ${ESLINT_DEPENDENCIES}; do
echo " - ${package}@$(get_js_package_version ${package})"
done
}
hook=${1}
if [ -z "${hook}" ]; then
echo >&2 "Usage: show-hook-dependencies.sh HOOK"
exit 1
fi
case "${hook}" in
"flake8") show_flake8_dependencies;;
"eslint") show_eslint_dependencies;;
*) echo >&2 "ERROR: Hook ${hook} not supported. Available choices: flake8, eslint. Exit..."; exit 1;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment