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

Code quality changes - Shellcheck #24

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

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.

gen.sh Outdated Show resolved Hide resolved
@@ -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.

examples/arithmetic/data/sample/testdata.yaml Outdated Show resolved Hide resolved
gen.sh Outdated Show resolved Hide resolved
gen.sh Outdated Show resolved Hide resolved
gen.sh Outdated Show resolved Hide resolved
examples/ninetynine/data/generator.sh Outdated Show resolved Hide resolved
gen.sh Outdated Show resolved Hide resolved
gen.sh Outdated Show resolved Hide resolved
@@ -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?

generator_example_acm.sh Outdated Show resolved Hide resolved
Tagl and others added 3 commits October 25, 2024 15:24
Co-authored-by: Simon Lindholm <[email protected]>
Co-authored-by: Simon Lindholm <[email protected]>
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