Shell code clean up jq script
shell

The current implementation first checks if the JSON is valid with `jq empty` and then formats it with `jq .`. This results in processing the same file twice with `jq`, which is inefficient. You can combine these steps into one by directly attempting to format the file. The `jq .` command will fail for invalid JSON, so you can use its exit code to determine if formatting was successful.
Additionally, when `jq` fails after a stream redirection (`>`), it can leave behind an empty temporary file. It's good practice to explicitly clean this up on failure.
```suggestion
echo "Attempting to beautify $file with jq..."
if jq . "$file" > "${file}.pretty" 2>/dev/null; then
mv "${file}.pretty" "$file"
echo "Beautification of $file complete."
else
rm -f "${file}.pretty"
echo "$file contains invalid JSON. Skipping beautification."
fi
```
_Originally posted by @gemini-code-assist[bot] in https://github.com/SalamLang/Salam/pull/1147#discussion_r2595249079_
0 条评论