Skip to content

Code quality changes - Shellcheck#24

Open
Tagl wants to merge 17 commits intoKodsport:masterfrom
Tagl:master
Open

Code quality changes - Shellcheck#24
Tagl wants to merge 17 commits intoKodsport:masterfrom
Tagl:master

Conversation

@Tagl
Copy link
Contributor

@Tagl Tagl commented Oct 16, 2024

I ran the code through shellcheck which is de facto standard static analysis tool for shell scripts.
I made the changes required to pass, only ignoring a few warnings for the special use cases.

Why did I do this?
We are using shellcheck and include testdata_tools in our repos for contests so the library got flagged.
For libraries it is important to make sure errors/warnings don't disrupt the experience of the library user.

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck source=/dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is something we want in examples. What does it do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It ensures that the shellcheck tool doesn't try to follow the path, since this path does not lead to a valid file in almost all cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does it not lead to a valid file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I thought this was on the other example files in the root, where the source paths there reference something that probably doesn't exist. Should those files even be there since these examples are given?

The issue here is working directory related. Running shellcheck from the scripts directory without this comment won't report any issues because the file exists.
The correct way to amend this is:

# shellcheck source-path=SCRIPTDIR

Which tells shellcheck to treat the path as if it were relative from the script's directory.

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck source=/dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does it not lead to a valid file?

Tagl and others added 3 commits October 25, 2024 15:24
Co-authored-by: Simon Lindholm <simon.lindholm10@gmail.com>
Co-authored-by: Simon Lindholm <simon.lindholm10@gmail.com>
Co-authored-by: Simon Lindholm <simon.lindholm10@gmail.com>
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.

3 participants