Skip to content

Commit

Permalink
YETUS-1169. improve i18n support
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here committed Apr 29, 2022
1 parent 03fdf8c commit 171aada
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions precommit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<excludes>
<exclude>src/main/python/unit-test-filter-file.example</exclude>
<exclude>src/test/resources/brokenfiles/**</exclude>
<exclude>src/test/resources/i18n/**</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion precommit/src/main/shell/core.d/change-analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function exclude_paths_from_changed_files
for p in "${EXCLUDE_PATHS[@]}"; do
if [[ "${f}" =~ ${p} ]]; then
strip=true
echo "${f}" >> "${PATCH_DIR}/excluded.txt"
printf "%b\n" "${f}" >> "${PATCH_DIR}/excluded.txt"
break
fi
done
Expand Down
17 changes: 10 additions & 7 deletions precommit/src/main/shell/plugins.d/codespell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,32 @@ function codespell_logic
declare repostatus=$1
declare -a codespellargs
declare i
declare tmpfile

tmpfile="${PATCH_DIR}/codespell.$$"

pushd "${BASEDIR}" >/dev/null || return 1

if [[ -f "${CODESPELL_X_FILE}" ]]; then
codespellargs=("--exclude-file" "${CODESPELL_X_FILE}")
fi

printf "^%b:\n" "${CHANGED_FILES[@]}" > "${tmpfile}"

# specifically add ./ because otherwise the .codespellrc file gets weird
"${CODESPELL}" \
--disable-colors \
--interactive 0 \
--quiet-level 2 \
"${codespellargs[@]}" \
"./${i}" \
"." \
| "${SED}" -e 's,^./,,g' \
>> "${PATCH_DIR}/${repostatus}-codespell-tmp.txt"

for i in "${CHANGED_FILES[@]}"; do
"${GREP}" -E "^${i}:" \
"${PATCH_DIR}/${repostatus}-codespell-tmp.txt" \
>> "${PATCH_DIR}/${repostatus}-codespell-result.txt"
done

"${GREP}" -E -f "${tmpfile}" \
"${PATCH_DIR}/${repostatus}-codespell-tmp.txt" \
>> "${PATCH_DIR}/${repostatus}-codespell-result.txt"
rm "${tmpfile}"
popd > /dev/null || return 1
}

Expand Down
14 changes: 2 additions & 12 deletions precommit/src/main/shell/plugins.d/detsecrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,11 @@ function detsecrets_calcdiffs
function detsecrets_convert_json_to_flat
{
declare repostatus=$1
declare filename
declare tmpfile

tmpfile="${PATCH_DIR}/detsecrets.$$"

for filename in "${CHANGED_FILES[@]}"; do
echo "${filename}" >> "${tmpfile}"
done

if [[ -f "${PATCH_DIR}/excluded.txt" ]]; then
stripcmd=("${GREP}" "-v" "-f" "${PATCH_DIR}/excluded.txt")
else
stripcmd=("cat")
fi
printf "^%b:\n" "${CHANGED_FILES[@]}" > "${tmpfile}"

# rip apart the detect-secrets json and make it a colon delimited file
# to make it easier to parse. Theoretically, python or python3 should
Expand All @@ -117,8 +108,7 @@ function detsecrets_convert_json_to_flat
"${pythonexec}" "${BINDIR}/plugins.d/detsecrets_parse.py" \
"${PATCH_DIR}/${repostatus}-detsecrets-result.json" \
"${DETSECRETS_HASHFILE}" \
| "${GREP}" "-f" "${tmpfile}" \
| "${stripcmd[@]}" \
| "${GREP}" -E -f "${tmpfile}" \
> "${PATCH_DIR}/${repostatus}-detsecrets-result.txt"

rm "${tmpfile}"
Expand Down
12 changes: 7 additions & 5 deletions precommit/src/main/shell/plugins.d/jshint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ EOF
function jshint_logic
{
declare repostatus=$1
declare j
declare full="${PATCH_DIR}/${repostatus}-jshint-result.full.txt"
declare filter="${PATCH_DIR}/${repostatus}-jshint-result.txt"
declare tmpfile

tmpfile="${PATCH_DIR}/jshint.$$"

pushd "${BASEDIR}" >/dev/null || return 1
"${JSHINT}" \
Expand All @@ -106,13 +108,13 @@ function jshint_logic
. \
> "${full}"

printf "^%b:\n" "${CHANGED_FILES[@]}" > "${tmpfile}"

# pull out the files we care about
for j in "${CHANGED_FILES[@]}"; do
"${GREP}" "^${j}:" "${full}" \
>> "${filter}"
done
"${GREP}" -E -f "${tmpfile}" "${full}" > "${filter}"

popd > /dev/null || return 1
rm "${tmpfile}"
}

function jshint_preapply
Expand Down
10 changes: 2 additions & 8 deletions precommit/src/main/shell/smart-apply-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ function patch_reports
find_changed_files

if [[ -n "${FILEREPORT}" ]]; then
: > "${FILEREPORT}"
for i in "${CHANGED_FILES[@]}"; do
echo "${i}" >> "${FILEREPORT}"
done
printf "%b\n" "${CHANGED_FILES[@]}" > "${FILEREPORT}"
fi

if [[ -n "${MODULEREPORT}" ]] || [[ -n "${UNIONREPORT}" ]]; then
Expand All @@ -281,10 +278,7 @@ function patch_reports
find_changed_modules

if [[ -n "${MODULEREPORT}" ]]; then
: > "${MODULEREPORT}"
for i in "${CHANGED_MODULES[@]}"; do
echo "${i}" >> "${MODULEREPORT}"
done
printf "%b\n" "${CHANGED_MODULES[@]}" > "${MODULEREPORT}"
fi

if [[ -n "${UNIONREPORT}" ]]; then
Expand Down
4 changes: 4 additions & 0 deletions precommit/src/test/resources/i18n/ß.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"test1": "test1",
"test2": "test2"
}
7 changes: 7 additions & 0 deletions precommit/src/test/resources/i18n/ä.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
test
-->
<test/>
6 changes: 6 additions & 0 deletions precommit/src/test/resources/i18n/ç.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# test
---

test:
- 1
- 2

0 comments on commit 171aada

Please sign in to comment.