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

Use Shellcheck to resolve violations code in Shell Script #11637

Open
14 of 33 tasks
Rahulkhinchi03 opened this issue May 15, 2022 · 12 comments
Open
14 of 33 tasks

Use Shellcheck to resolve violations code in Shell Script #11637

Rahulkhinchi03 opened this issue May 15, 2022 · 12 comments

Comments

@Rahulkhinchi03
Copy link
Member

Rahulkhinchi03 commented May 15, 2022

ShellCheck is an open-source static analysis tool that automatically finds bugs in your shell scripts. (https://github.com/koalaman/shellcheck)

For more information on Code: https://gist.github.com/nicerobot/53cee11ee0abbdc997661e65b348f375#file-_shellcheck-md

./.ci/*sh has all the shell scripts files and we have all the disabled violations at the .shellcheckrc file.
We are currently invoking spellcheck through Terminal (You can download (https://github.com/koalaman/shellcheck#installing) it through apt or similar package managers on local). We have integrated Shellcheck with GitHub action https://github.com/checkstyle/checkstyle/actions/workflows/shellcheck.yml

TO-DO:

# until https://github.com/checkstyle/checkstyle/issues/11637
disable=SC2086 # (info): Double quote to prevent globbing and word splitting.

  • Pick a suppression (single suppression fix in single Pull Request) To allocate a suppression update for you please make comment in the issue "I am on "SCxxxxSuppression"
  • Remove Your Selected Suppression from the .shellcheckrc file.
  • Run shellcheck through Terminal and See Errors
  • Fix the Errors and make a PR.

LIST OF SUPPRESSIONS:

  • SC2086 # (info): Double quote to prevent globbing and word splitting.
  • SC2006 # (style): Use $(...) notation instead of legacy backticks ....
  • SC2046 # (warning): Quote this to prevent word splitting.
  • SC2207 # (warning): Prefer mapfile or read -a to split command output.
  • SC2002 # (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
  • SC2061 # (warning): Quote the parameter to -name so the shell won't interpret it.
  • SC2035 # (info): Use ./glob or -- glob so names with dashes won't become options.
  • SC2236 # (style): Use -n instead of ! -z.
  • SC2016 # (info): Expressions don't expand in single quotes, use double quotes for that.
  • SC2185 # (info): Some finds don't have a default path. Specify '.' explicitly.
  • SC2155 # (warning): Declare and assign separately to avoid masking return values.
  • SC2071 # (error): > is for string comparisons. Use -gt instead.
  • SC2034 # (warning): RUN_JOB appears unused. Verify use (or export if used externally).
  • SC2216 # (warning): Piping to 'true', a command that doesn't read stdin.
  • SC2013 # (info): To read lines rather than words, pipe/redirect to a 'while read' loop.
  • SC2206 # (warning): Quote to prevent word splitting/globbing.
  • SC2143 # (style): Use grep -q instead of comparing output with [ -n .. ].
  • SC2004 # (style): $/${} is unnecessary on arithmetic variables.
  • SC2087 # (warning): Quote 'EOF' to make here document expansions happen on the server-side.
  • SC2102 # (info): Ranges can only match single chars (mentioned due to duplicates).
  • SC2242 # (error): Can only exit with status 0-255.
  • SC2115 # (warning): Use "${var:?}" to ensure this never expands to /* .
  • SC2128 # (warning): Expanding an array without an index only gives the first element.
  • SC2063 # (warning): Grep uses regex, but this looks like a glob.
  • SC2126 # (style): Consider using grep -c instead of grep|wc -l.
  • SC2088 # (warning): Tilde does not expand in quotes. Use $HOME.
  • SC2005 # (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
  • SC2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
  • SC2026 # (info): This word is outside of quotes.
  • SC2269 # (info): This variable is assigned to itself, so the assignment does nothing.
  • SC2230: which is non-standard. Use builtin 'command -v' instead.
  • SC2153: Possible Misspelling: MYVARIABLE may not be assigned, but MY_VARIABLE is.
  • SC1004: This backslash+linefeed is literal. Break outside single quotes if you want to break the line.

Example of expected update with removal of suppression: 5ea26d6

@Rahulkhinchi03 Rahulkhinchi03 changed the title Use Shellcheck to resolve shell script violations Use Shellcheck to resolve violations in Shell Script May 15, 2022
@Rahulkhinchi03 Rahulkhinchi03 changed the title Use Shellcheck to resolve violations in Shell Script Use Shellcheck to resolve violations code in Shell Script May 15, 2022
@Rahulkhinchi03
Copy link
Member Author

@romani @rnveach @nick-mancuso The wercker.sh violations are excluded in the issue as #11564

@romani
Copy link
Member

romani commented May 17, 2022

@Rahulkhinchi03, please send single PR to resolve all violations of single rule to show example how to fix violations and remove suppression.

@Rahulkhinchi03
Copy link
Member Author

Rahulkhinchi03 commented Jun 8, 2022

@romani @nick-mancuso @rnveach
Before the Project gets started, Should I resolve all the shell code errors in the release.sh file by creating PR?

@romani
Copy link
Member

romani commented Jun 9, 2022

Yes, but Better to slice a work by rules to let us activate rule and make sure nobody will introduce problems again.

@Rahulkhinchi03
Copy link
Member Author

Rahulkhinchi03 commented Jun 9, 2022

Sure, I can see that release.sh has error codes: SC2086, SC2006

@stoyanK7
Copy link
Collaborator

I am on SC2269 and SC2046

@Rahulkhinchi03
Copy link
Member Author

@stoyanK7 That's really great!
Please make different PRs for both the ERROR CODES.

@ThatSneakyCoder
Copy link
Contributor

I'm on SC2005

ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Jan 29, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Feb 18, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Feb 23, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Feb 23, 2023
Zopsss pushed a commit to Zopsss/checkstyle that referenced this issue Mar 2, 2023
Zopsss pushed a commit to Zopsss/checkstyle that referenced this issue Mar 2, 2023
Zopsss pushed a commit to Zopsss/checkstyle that referenced this issue Mar 2, 2023
Zopsss pushed a commit to Zopsss/checkstyle that referenced this issue Mar 2, 2023
Zopsss pushed a commit to Zopsss/checkstyle that referenced this issue Mar 2, 2023
@ThatSneakyCoder
Copy link
Contributor

ThatSneakyCoder commented Mar 14, 2023

@romani

Kindly update the checklist. Shellcheck SC2006 is already resolved but, not checked in the checklist(#11637....)

@ThatSneakyCoder
Copy link
Contributor

I'm on SC2002, SC2016, SC2061.

ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Mar 14, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Mar 14, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Mar 14, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Mar 14, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Mar 14, 2023
romani pushed a commit that referenced this issue Mar 15, 2023
@github-actions github-actions bot modified the milestones: 10.3, 10.8.2 Mar 15, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Mar 15, 2023
romani pushed a commit that referenced this issue Mar 15, 2023
ThatSneakyCoder added a commit to ThatSneakyCoder/checkstyle that referenced this issue Mar 20, 2023
romani pushed a commit that referenced this issue Mar 20, 2023
@github-actions github-actions bot removed this from the 10.9.0 milestone Mar 20, 2023
7h3-3mp7y-m4n pushed a commit to 7h3-3mp7y-m4n/checkstyle that referenced this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants