mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.1k stars 336 forks source link

syntax: same shellscript produce different error messages on different OSes #887

Closed JounQin closed 2 years ago

JounQin commented 2 years ago
#!/usr/bin/env bash
set -euo pipefail

monorepo_path="$("$(dirname "$(realpath -s "$0")")/../functions/monorepo_path")"

if [[ "$(pwd)" != "$monorepo_path" ]]; then
    cd "$monorepo_path"
fi

# name-only https://stackoverflow.com/a/1552353
# staged https://stackoverflow.com/a/1587877
# filter https://stackoverflow.com/a/41730200
# no-pager https://stackoverflow.com/a/2183920
# ignore path https://stackoverflow.com/questions/5685007/making-git-log-ignore-changes-for-certain-paths/21079437#21079437
echo ""
read -r -a en_translation_files < <(
    # cspell:disable-next-line
    git --no-pager diff --cached --name-only --diff-filter='ACMRTUXB' -- 'packages/translations/en'
    echo
)
declare -p en_translation_files

echo ""
read -r -a other_translation_files < <(
    # cspell:disable-next-line
    git --no-pager diff --cached --name-only --diff-filter='ACMRTUXB' -- ':!packages/translations/en' 'packages/translations'
    echo
)
declare -p other_translation_files

echo ""
default_locale="$(node -p "require('@configs/locales').defaultLocale;")"
read -r -a other_translation_folders < <(find "packages/translations" -not -name "$default_locale" -mindepth 1 -maxdepth 1 -type d)
declare -p other_translation_folders

# sanity check
en_translation_files_length="${#en_translation_files[@]}"
other_translation_files_length="${#other_translation_files[@]}"
other_translation_folders_length="${#other_translation_folders[@]}"

# math https://unix.stackexchange.com/a/299326
if [[ "$((en_translation_files_length * other_translation_folders_length))" -gt $other_translation_files_length ]]; then
    echo "[check]: unequal number of translation files" >&2
    exit 1
fi

# declare -A folder_changed_file_counts
# for translation_folder in "${other_translation_folders[@]}"; do
#     echo "$translation_folder"
#     locale="${translation_folder##*/}"
#     echo "$locale"
# done

macOS

"foo(" must be followed by )

Ubuntu

reached EOF without closing quote "

See https://github.com/rx-ts/prettier/runs/7057779737?check_suite_focus=true#step:6:41

mvdan commented 2 years ago

Are you absolutely positive that the bytes fed to the parser are exactly the same? I would print them out in quoted form as part of the CI test, and then ensure that Ubuntu and Mac really are parsing the same bytes.

The parser is entirely platform-agnostic, so I would be very surprised if it was to blame here. My guess is that it's something above the parser that is slightly changing the input bytes, such as a shell script.

JounQin commented 2 years ago

Are you absolutely positive that the bytes fed to the parser are exactly the same? I would print them out in quoted form as part of the CI test, and then ensure that Ubuntu and Mac really are parsing the same bytes.

Make sense, I'll do it later.

The parser is entirely platform-agnostic, so I would be very surprised if it was to blame here. My guess is that it's something above the parser that is slightly changing the input bytes, such as a shell script.

The test is running with jest, so I don't expect any difference between the input bytes, but yeah, it could be possible, I'll check it to confirm first.

mvdan commented 2 years ago

I'm going to close this for now, because I see no indication that there's a bug in our code, and I don't have enough to investigate further. We can easily reopen if you find more information.