Skip to content

Fix 'shellcheck' complaints#193

Merged
sinnykumari merged 2 commits intocoreos:masterfrom
miabbott:shellcheck_fixes
Nov 9, 2018
Merged

Fix 'shellcheck' complaints#193
sinnykumari merged 2 commits intocoreos:masterfrom
miabbott:shellcheck_fixes

Conversation

@miabbott
Copy link
Copy Markdown
Member

@miabbott miabbott commented Nov 5, 2018

@miabbott
Copy link
Copy Markdown
Member Author

miabbott commented Nov 5, 2018

Inspired by Luca's comment, I took a stab at correcting most of the shellcheck complaints.

But I haven't actually verified everything works yet, so WIP

@cgwalters
Copy link
Copy Markdown
Member

Seems sane, I didn't see any problems offhand just skimming it. But today we don't have any CI so...please do test it.

I'd probably say we should aim to land this after #190 since this is a nice-to-have but that's more critpath.

@miabbott
Copy link
Copy Markdown
Member Author

miabbott commented Nov 5, 2018

Seems sane, I didn't see any problems offhand just skimming it. But today we don't have any CI so...please do test it.

Yeah, I'd like to land this eventually as a start for some basic CI syntax checking/linting.

Copy link
Copy Markdown
Contributor

@sinnykumari sinnykumari left a comment

Choose a reason for hiding this comment

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

LGTM
Nice work @miabbott !

@dustymabe
Copy link
Copy Markdown
Member

thanks @cgwalters and @sinnykumari for the review. I will merge this after #190 is merged and this is rebased.

@dustymabe
Copy link
Copy Markdown
Member

@miabbott - does the WIP in the title of this PR indicate you are planning future changes, or that you want to wait until after #190 ?

@miabbott
Copy link
Copy Markdown
Member Author

miabbott commented Nov 6, 2018

@dustymabe I'm still making more changes...forgot to check some of the other bash scripts...I'm in deep now. 😆

Let's wait until after #190 and I'll rebase and re-run shellcheck against those changes. Will let you know when this is good to go.

@miabbott miabbott changed the title WIP: Fix 'shellcheck' complaints Fix 'shellcheck' complaints Nov 8, 2018
@miabbott
Copy link
Copy Markdown
Member Author

miabbott commented Nov 8, 2018

This should be ready for review. Most of the changes are just around double-quoting variables in the bash scripts, but there are some re-working of piping output to commands. I tried to link to the shellcheck wiki where the syntax changes got gnarly; let me know if additional info is necessary.

Once this lands, I'd like to eventually setup a TravisCI job that will run shellcheck on incoming PRs.

@dustymabe
Copy link
Copy Markdown
Member

since she started it I'll let sinny finish the review tomorrow..

one positive note: it looks like shellcheck is in fedora: https://apps.fedoraproject.org/packages/ShellCheck

@miabbott
Copy link
Copy Markdown
Member Author

miabbott commented Nov 8, 2018

one positive note: it looks like shellcheck is in fedora: https://apps.fedoraproject.org/packages/ShellCheck

Yup! I was running that in a container (obviously!)

Copy link
Copy Markdown
Contributor

@sinnykumari sinnykumari left a comment

Choose a reason for hiding this comment

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

One comment other than that looks good!

Comment thread src/libguestfish.sh
coreos_gf_launch "$@"
coreos_gf run
local root=$(coreos_gf findfs-label root)
local root
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious, is there an advantage of declaring and defining local variable in separate line? If yes, maybe we should also change it at places like https://github.com/coreos/coreos-assembler/pull/193/files#diff-496abb20f29d0275d6697b14356e60e1R131

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, it's one of the things that shellcheck flags

https://github.com/koalaman/shellcheck/wiki/SC2155

Admittedly, I did notice that it didn't always flag what appeared to be "offending" code, but didn't dig into the why.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I could be more thorough and find all the local assignments and change them to match, if that seems reasonable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, it's only a problem if one is executing a subprocess basically, in other words local vmpreparedir=${workdir}/tmp/supermin.prepare is fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, yup...that looks like the reasoning!

Comment thread src/cmd-build
# on the `mv`.
touch .build-commit
mv -T ${tmp_builddir} ${buildid}
mv -T "${tmp_builddir:?}" "${buildid}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, why the explicit :? here? We're using set -u so that behavior applies everywhere right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(It doesn't hurt though, I'm fine leaving this as is)

Copy link
Copy Markdown
Member Author

@miabbott miabbott Nov 9, 2018

Choose a reason for hiding this comment

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

https://github.com/koalaman/shellcheck/wiki/SC2154

I used the guidance at the bottom:

If you know for a fact that the variable is set, you can use ${var:?} to fail if the variable is unset (or empty), or explicitly initialize/declare it with var="" or declare var.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, so if I have the shellcheck directive at the top of the file # shellcheck source=src/cmdlib.sh, this warning doesn't get thrown any more. Leaving the :? doesn't seem to hurt it either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah ok!

@cgwalters
Copy link
Copy Markdown
Member

LGTM, @sinnykumari - do you want to do the merge?

@sinnykumari sinnykumari merged commit 51c715c into coreos:master Nov 9, 2018
@dustymabe
Copy link
Copy Markdown
Member

🎆

@jlebon
Copy link
Copy Markdown
Member

jlebon commented Nov 19, 2018

Sweet, this looks cool!

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.

5 participants