-
-
Notifications
You must be signed in to change notification settings - Fork 5
Use jq's sort to ensure consistent cross-platform sort behavior
#38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hello 👋 Thanks for your PR. This repo does not currently have dedicated maintainers. Our guardians team will attempt to review and merge your PR, but it will likely take longer for your PR to be reviewed. If you enjoy contributing to Exercism and have a track-record of doing so successfully, you might like to become an Exercism maintainer for this track. Please feel free to ask any questions, or chat to us about anything to do with this PR or the reviewing process on the Exercism forum. (cc @exercism/guardians) |
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
|
|
Nice, removes dependence on |
jq's sort to ensure cross-platform sort behavior
jq's sort to ensure cross-platform sort behaviorjq's sort to ensure consistent cross-platform sort behavior
| has_message=$(jq 'has("message") and .message != null' "$results_file_path") | ||
|
|
||
| if [ "$has_message" = "true" ]; then | ||
| jq '.message = (.message|split("\n")|map(sub("^[ \t]+"; "")|select(. != ""))|sort|join("\n"))' "$results_file_path" > "$results_file_path.tmp" | ||
| mv "$results_file_path.tmp" "$results_file_path" | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| has_message=$(jq 'has("message") and .message != null' "$results_file_path") | |
| if [ "$has_message" = "true" ]; then | |
| jq '.message = (.message|split("\n")|map(sub("^[ \t]+"; "")|select(. != ""))|sort|join("\n"))' "$results_file_path" > "$results_file_path.tmp" | |
| mv "$results_file_path.tmp" "$results_file_path" | |
| fi | |
| jq '.message = ( | |
| .message // "" | split("\n") | map(ltrim | select(. != "") | |
| ) | sort | join("\n")) | | |
| if .message == "" then del(.message) end | |
| ' "$results_file_path" > "$results_file_path.tmp" | |
| mv "$results_file_path.tmp" "$results_file_path" |
This works, too :) No need for multiple jq commands of shell conditions.
Note, this requires jq 1.7+ for the if line. On older jq versions, you need an else . end
No description provided.