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

Run shellcheck on scripts #214

Merged
merged 13 commits into from
Dec 28, 2021
Merged

Run shellcheck on scripts #214

merged 13 commits into from
Dec 28, 2021

Conversation

szepeviktor
Copy link
Contributor

Description

Check common problems in our shell code.
@ramsey Should I go on and fix reported problems?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

PR checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING.md document.
  • I have added tests to cover my changes.

@codecov
Copy link

codecov bot commented Dec 28, 2021

Codecov Report

Merging #214 (bcc7d0e) into v2 (6e86502) will not change coverage.
The diff coverage is n/a.

❗ Current head bcc7d0e differs from pull request most recent head b388d98. Consider uploading reports for the commit b388d98 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##               v2     #214   +/-   ##
=======================================
  Coverage   88.70%   88.70%           
=======================================
  Files           5        5           
  Lines         124      124           
=======================================
  Hits          110      110           
  Misses         14       14           

@ramsey
Copy link
Owner

ramsey commented Dec 28, 2021

Should I go on and fix reported problems?

Sounds good to me. Please do.

Be careful where it mentions needing to double quote to prevent globbing, etc. There are a few places where I'm intentionally not double-quoting, but if you're able to find a way that makes shellcheck happy and keeps the tests passing, then awesome!

@szepeviktor
Copy link
Contributor Author

There are a few places where I'm intentionally not double-quoting

It is very easy

"${var[@]}" === "arg1" "arg2" "arg3"
"${var[*]}" === "arg1 arg2 arg3"

@szepeviktor szepeviktor marked this pull request as ready for review December 28, 2021 08:34
@szepeviktor
Copy link
Contributor Author

Please also see #215

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Dec 28, 2021

It is harder than I thought! 🥊

Not quoting is used to split string at whitespaces.

@szepeviktor szepeviktor marked this pull request as draft December 28, 2021 09:30
@szepeviktor
Copy link
Contributor Author

szepeviktor commented Dec 28, 2021

How about making a key this way?

function make_key {
    tr --squeeze-repeats '\t ' '-' <<<"${*}"
}

@szepeviktor
Copy link
Contributor Author

The above 👆 function does not exclude empty string elements of an array 😿

@szepeviktor
Copy link
Contributor Author

... this feel like my private war against unquoted variables 🪖

@ramsey
Copy link
Owner

ramsey commented Dec 28, 2021

How about making a key this way?

I was trying to go for a pure Bash solution, so I don't have to rely on external tools.

@ramsey
Copy link
Owner

ramsey commented Dec 28, 2021

The shell scripts need to run on GitHub's Windows environments, so any tools that don't exist there aren't going to work.

@szepeviktor szepeviktor marked this pull request as ready for review December 28, 2021 19:37
Copy link
Owner

@ramsey ramsey left a comment

Choose a reason for hiding this comment

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

This is great! Thanks!

for option in "${additional_options[@]}"; do
composer_options+=("${option}")
done
read -r -a additional_options <<<"${additional_composer_options}"
Copy link
Owner

Choose a reason for hiding this comment

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

Oh, nice! I didn't think about using redirection with read. I was thinking of it only in terms of user interaction.

@ramsey ramsey merged commit 89752f0 into ramsey:v2 Dec 28, 2021
@szepeviktor szepeviktor deleted the patch-1 branch December 28, 2021 20:16
@szepeviktor
Copy link
Contributor Author

Thank you!

While working on it I've realized Bash should handle command line arguments through getopts.

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.

None yet

2 participants