Skip to content

Commit cb3f318

Browse files
committed
Merge branch 'fix-switches' of github.com:johnseekins/ice_detention_scraper into fix-switches
2 parents c1b6142 + b664e07 commit cb3f318

10 files changed

Lines changed: 238 additions & 23 deletions

.config/mise.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ lefthook = "latest"
44
yamllint = "latest"
55
actionlint = "latest"
66
shellcheck = "latest"
7+
markdownlint-cli2 = "latest"
8+
jq = "latest"

.lefthook.yml

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,66 @@
1+
# Refer for explanation to following link:
2+
# https://lefthook.dev/configuration/
13
pre-commit:
4+
parallel: true
25
jobs:
6+
- name: shell script validation
7+
run: shellcheck --shell=bash -x {staged_files}
8+
glob:
9+
- "*.sh"
10+
- "*.zsh"
11+
- "*.bash"
12+
13+
- name: dockerfile linting
14+
run: hadolint {staged_files}
15+
glob:
16+
- "Dockerfile"
17+
- "**/Dockerfile"
18+
19+
- name: markdown linting
20+
run: markdownlint-cli2 --fix --config .markdownlint.json {staged_files}
21+
glob:
22+
- "*.md"
23+
stage_fixed: true
24+
325
- name: yaml linting
426
run: yamllint -c .yamllint-config.yaml .
527
glob: "*.y*ml"
28+
629
- name: Github Action linting
730
run: actionlint
8-
include:
31+
glob:
932
- ".github/workflows/*.y*ml"
33+
1034
- name: Ruff Formatting
1135
run: uv run ruff format -q .
12-
glob: "*.py"
36+
glob:
37+
- "*.py"
38+
stage_fixed: true
39+
1340
- name: Ruff Syntax checking
1441
run: uv run ruff check --fix -q
15-
glob: "*.py"
42+
glob:
43+
- "*.py"
44+
stage_fixed: true
45+
1646
- name: MyPy type validation
1747
run: uv run mypy .
18-
glob: "*.py"
48+
glob:
49+
- "*.py"
50+
51+
- name: json validation
52+
run: tools/check-json.sh {staged_files}
53+
glob:
54+
- "*.json"
55+
56+
- name: check for merge conflicts
57+
run: tools/check-merge-conflicts.sh {staged_files}
58+
59+
- name: check for bad file details
60+
run: tools/check-file-details.sh {staged_files}
61+
stage_fixed: true
62+
63+
output:
64+
- success
65+
- failure
66+
- summary

.pre-commit-config.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

main.py

100644100755
File mode changed.

tools/.library.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
LC_ALL=C
5+
export LC_ALL
6+
7+
function git_files {
8+
FILES=$(git ls-files --exclude-standard)
9+
FILES+=" $(git ls-files --exclude-standard --others)"
10+
echo "${FILES}"
11+
}

tools/check-file-details.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
set -eou pipefail
4+
5+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
pushd "${SCRIPT_DIR}" > /dev/null || exit 1
7+
pushd "$(git rev-parse --show-toplevel)" > /dev/null || exit 1
8+
9+
. tools/.library.sh
10+
11+
if [[ $# -eq 0 ]]; then
12+
FILES=$(git_files | xargs)
13+
else
14+
FILES=$*
15+
fi
16+
SHEBANG_FIXED=()
17+
WHITESPACE_TO_FIX=()
18+
# default to 5 MB
19+
FILE_SIZE=${FILE_SIZE:-5000000}
20+
TOO_BIG=()
21+
exit_code=0
22+
23+
for fn in ${FILES}; do
24+
set +e
25+
shebang=$(grep -l "^#!/" "${fn}")
26+
if [[ -n "${shebang}" && ! -x "${fn}" ]]; then
27+
chmod +x "${fn}"
28+
SHEBANG_FIXED+=("${fn}")
29+
exit_code=1
30+
fi
31+
set +e
32+
# grep exits non-0 when it doesn't find anything
33+
whitespace=$(grep -l ' +$' "${fn}")
34+
set -e
35+
if [[ -n "${whitespace}" ]]; then
36+
WHITESPACE_TO_FIX+=("${whitespace}")
37+
exit_code=1
38+
fi
39+
size=$(stat --printf="%s" "${fn}")
40+
if [[ "${size}" -gt "${FILE_SIZE}" ]]; then
41+
TOO_BIG+=("${fn}: ${size}")
42+
exit_code=1
43+
fi
44+
done
45+
46+
if [[ "${#SHEBANG_FIXED[@]}" -gt 0 ]]; then
47+
echo "Fixed executable bit on:"
48+
printf '\t%s\n' "${SHEBANG_FIXED[@]}"
49+
fi
50+
if [[ "${#WHITESPACE_TO_FIX[@]}" -gt 0 ]]; then
51+
echo "Should clean whitespace on:"
52+
printf '\t%s\n' "${WHITESPACE_TO_FIX[@]}"
53+
fi
54+
55+
if [[ "${#TOO_BIG[@]}" -gt 0 ]]; then
56+
echo "Files larger than ${FILE_SIZE}:"
57+
printf '\t%s\n' "${TOO_BIG[@]}"
58+
fi
59+
60+
popd > /dev/null || exit 1
61+
popd > /dev/null || exit 1
62+
exit "${exit_code}"

tools/check-json.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
set -eou pipefail
4+
5+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
pushd "${SCRIPT_DIR}" > /dev/null || exit 1
7+
pushd "$(git rev-parse --show-toplevel)" > /dev/null || exit 1
8+
9+
. tools/.library.sh
10+
11+
if [[ $# -eq 0 ]]; then
12+
FILES=$(git_files | grep "json$" | xargs)
13+
else
14+
FILES=$*
15+
fi
16+
17+
exit_code=0
18+
for fn in ${FILES}; do
19+
set +e
20+
error=$(jq '.' "${fn}" 2>&1 > /dev/null)
21+
set -e
22+
if [[ -n "${error}" ]]; then
23+
printf "Failure reading %s\n\t%s\n" "${fn}" "${error}"
24+
exit_code=1
25+
fi
26+
done
27+
28+
popd > /dev/null || exit 1
29+
popd > /dev/null || exit 1
30+
exit "${exit_code}"

tools/check-merge-conflicts.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
set -eou pipefail
4+
5+
gitdir=$(git rev-parse --git-dir)
6+
# if we aren't actively merging, there's no reason to check for conflict artifacts
7+
if [[ ! -f "${gitdir}/MERGE_MSG" && ! -f "${gitdir}/MERGE_HEAD" && ! -f "${gitdir}/rebase-apply" && ! -f "${gitdir}/rebase-merge" ]]; then
8+
exit 0
9+
fi
10+
11+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
12+
pushd "${SCRIPT_DIR}" > /dev/null || exit 1
13+
pushd "$(git rev-parse --show-toplevel)" > /dev/null || exit 1
14+
15+
. tools/.library.sh
16+
17+
if [[ $# -eq 0 ]]; then
18+
FILES=$(git_files | xargs)
19+
else
20+
FILES=$*
21+
fi
22+
23+
patterns=( \
24+
"<<<<<<< "\
25+
"======= "\
26+
"=======\r\n" \
27+
"=======\n" \
28+
">>>>>>> " \
29+
)
30+
31+
exit_code=0
32+
for fn in ${FILES}; do
33+
for pattern in "${patterns[@]}"; do
34+
set +e
35+
error=$(grep "${pattern}" "${fn}" 2>&1 > /dev/null)
36+
set -e
37+
if [[ -n "${error}" ]]; then
38+
printf "%s may have merge conflict artifacts\n\t%s\n" "${fn}" "${error}"
39+
exit_code=1
40+
break
41+
fi
42+
done
43+
done
44+
45+
popd > /dev/null || exit 1
46+
popd > /dev/null || exit 1
47+
exit "${exit_code}"

tools/check-whitespace.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -eou pipefail
4+
5+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
pushd "${SCRIPT_DIR}" > /dev/null || exit 1
7+
pushd "$(git rev-parse --show-toplevel)" > /dev/null || exit 1
8+
9+
. tools/.library.sh
10+
11+
if [[ $# -eq 0 ]]; then
12+
FILES=$(git_files | xargs)
13+
else
14+
FILES=$*
15+
fi
16+
17+
TO_FIX=()
18+
exit_code=0
19+
set +e
20+
for fn in ${FILES}; do
21+
found=$(grep -l ' +$' "${fn}")
22+
if [[ -n "${found}" ]]; then
23+
TO_FIX+=("${found}")
24+
exit_code=1
25+
fi
26+
done
27+
set -e
28+
29+
if [[ "${#TO_FIX[@]}" -gt 0 ]]; then
30+
printf '%s\n' "${TO_FIX[@]}"
31+
fi
32+
popd > /dev/null || exit 1
33+
popd > /dev/null || exit 1
34+
exit "${exit_code}"

tools/find_missing_vera.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)