Skip to content
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

Fixing some style issues in shell scripts with shellcheck #77290

Closed
tesuji opened this issue Sep 28, 2020 · 12 comments
Closed

Fixing some style issues in shell scripts with shellcheck #77290

tesuji opened this issue Sep 28, 2020 · 12 comments
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Sep 28, 2020

There are some style issues in shell scripts in this repository.
ShellCheck is an useful tool to find bugs in shell scripts.
One could run git ls-files '*.sh' to find all shell script files and pipe the result to xargs shellcheck.
Or just fix it file-by-file.

Note that this issue doesn't talk about including shellcheck tests in CI.

@rustbot modify labels: E-easy E-mentor T-infra

@rustbot rustbot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels Sep 28, 2020
@pta2002
Copy link

pta2002 commented Sep 28, 2020

Can I have a go at this? I think I can work on it.

@tesuji
Copy link
Contributor Author

tesuji commented Sep 28, 2020

Sure. But it's known that there are some false-positive suggestions in shellcheck.
Most of them should be caught by CI (by falling to execute).

@pta2002
Copy link

pta2002 commented Sep 28, 2020

Alright, I'll have a look at what fails CI then!

@jyn514 jyn514 added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Sep 28, 2020
@pta2002
Copy link

pta2002 commented Sep 28, 2020

Just a question, I've reached src/ci/docker/scripts/android-start-emulator.sh, which starts with a shebang referencing #!/bin/sh instead of the usual #!/usr/bin/env bash, and then goes on to use &>, which shellcheck warns is not a thing on POSIX sh. Should this be changed to bash or is there a reason for this?

@pta2002
Copy link

pta2002 commented Sep 28, 2020

Also, what should I do about the unused variables that pop up here and there? Some like TARGET seem like they might be nice keeping if not just for making the file follow the same structure as the others, but since they're unused I'm not sure if I should delete them.

@tesuji
Copy link
Contributor Author

tesuji commented Sep 29, 2020

then goes on to use &>, which shellcheck warns is not a thing on POSIX sh

Just use 2>&1 instead. I don't know if android has bash, so let's keep it sh.

unused variables that pop up here and there

You could grep for the unused variables in src/ci.
Most of them should be passed via environment variables.
You could ignore unused var warnings.

@pta2002
Copy link

pta2002 commented Sep 29, 2020

So if they're unused they should probably be exported then, no? The ones shellcheck is warning about aren't

@tesuji
Copy link
Contributor Author

tesuji commented Sep 29, 2020

You could remove it. File a draft PR to see if it run successfully.

@sasurau4
Copy link
Contributor

sasurau4 commented Nov 2, 2020

The previous PR seems abondoned, I'll try it.

@jyn514
Copy link
Member

jyn514 commented Nov 2, 2020

The previous PR seems abondoned, I'll try it.

@sasurau4 the PR wasn't abandoned, it was rejected because it wasn't clear the improvements were worth the potential breakage. I see in #78666 you only fixed warnings shellcheck marked as 'error's, that might have a better chance.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 6, 2020
…n514

Fix shellcheck error

## Overview

Helps with rust-lang#77290

This pr fix only errors of shellcheck, the result of `git ls-files '*.sh' | xargs shellcheck --severity=error`.

Fixing error are following.

- https://github.com/koalaman/shellcheck/wiki/SC2148
- https://github.com/koalaman/shellcheck/wiki/SC1008

Disable error following.
- https://github.com/koalaman/shellcheck/wiki/SC2068
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Nov 27, 2020
…n514

Fix shellcheck error

## Overview

Helps with rust-lang#77290

This pr fix only errors of shellcheck, the result of `git ls-files '*.sh' | xargs shellcheck --severity=error`.

Fixing error are following.

- https://github.com/koalaman/shellcheck/wiki/SC2148
- https://github.com/koalaman/shellcheck/wiki/SC1008

Disable error following.
- https://github.com/koalaman/shellcheck/wiki/SC2068
@sjakobi
Copy link
Contributor

sjakobi commented Mar 26, 2021

Is there still work to do here now that #78666 has been merged?

@JohnTitor
Copy link
Member

Triage: #78666 fixed the shellcheck errors and I don't think it's much worth applying shellcheck's suggestions to our source, while fighting a lot of regressions, so I'm going to close the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants