Skip to content

Fix lint errors for src/tools/rustfmt/ci/integration.sh #143512

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

Closed
wants to merge 1 commit into from

Conversation

GuillaumeGomez
Copy link
Member

I think I'm going through shell lints errors one file at a time. Will make review much easier and hopefully will prevent me from adding some unwanted side effets.

r? @Kobzol

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2025

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@Kobzol
Copy link
Member

Kobzol commented Jul 6, 2025

I am not at all well-versed at bash and thus I am not very confident in reviewing such changes :( I would be just piping the PR diff into ChatGPT to even understand it, but that's not a very good reviewing strategy for such potentially subtle changes.

@GuillaumeGomez
Copy link
Member Author

In this case, I can walk you through them. :)

@@ -2,7 +2,7 @@

set -ex

: ${INTEGRATION?"The INTEGRATION environment variable must be set."}
: "${INTEGRATION?'The INTEGRATION environment variable must be set.'}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In shell, simple quote strings are literals, whereas double quote strings are an equivalent of format!.

So now, variables (${}) are interpreted as strings, so if they contain whitespace characters, it might break the script. Hence why we're putting them in double quote strings so they are treated as one string.

@@ -42,8 +42,9 @@ function check_fmt_with_lib_tests {

function check_fmt_base {
local test_args="$1"
local build=$(cargo test $test_args 2>&1)
if [[ "$build" =~ "build failed" ]] || [[ "$build" =~ "test result: FAILED." ]]; then
local build
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint says that we should not run a command while declaring a variable, so instead I declared the variable then assign it a value in the next line.

if [[ "$build" =~ "build failed" ]] || [[ "$build" =~ "test result: FAILED." ]]; then
local build
build=$(cargo test "$test_args" 2>&1)
if [[ "$build" =~ "build failed" ]] || [[ "$build" =~ test\ result\:\ FAILED\. ]]; then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two lints here: variables in double quote strings and the most important one is:

=~ test\ result\:\ FAILED\.

=~ means it's a regex check and the lint prefers to not have strings to ensure it doesn't have variables which could contain characters that might be interpreted as regex special characters (like the . here). So instead, we remove the quotes and escape the whitespace characters to keep it as one string and also escape characters that could be considered as regex special characters.

@@ -53,67 +54,72 @@ function check_fmt_base {
return 1
fi
cat rustfmt_output
! cat rustfmt_output | grep -q "internal error"
if [[ $? != 0 ]]; then
grep -q "internal error" < rustfmt_output
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint was complaining about the cat redirection which could be replaced by < rustfmt_output. And then I removed the ! operator and reverted the checked value (from != 0 to == 0). Less tricky to understand (if the command didn't fail, ie grep found the string, then not good). ^^'

! cat rustfmt_output | grep -q "internal error"
if [[ $? != 0 ]]; then
grep -q "internal error" < rustfmt_output
cmd_ret=$?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint was complaining that we were using $? and that it could be problematic since the last run command might not be the one expected. So instead, we store the value in a variable and then use this variable.

@GuillaumeGomez
Copy link
Member Author

And with these comments, I covered all lint cases. :)

If you still don't think you're the right person to review it, don't hesitate to assign someone else.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 6, 2025

@GuillaumeGomez can you close this and open a PR directly in https://github.com/rust-lang/rustfmt

@GuillaumeGomez
Copy link
Member Author

Sure.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2025
@GuillaumeGomez GuillaumeGomez deleted the shell-lints branch July 6, 2025 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants