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

feat: support shell scripts with no extension, fix perl shebang regex #4076

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
- Embed vulnerability database in Docker Image for running trivy on internet-free network
- Retry 5 times after 3 seconds in case of TooManyRequests when downloading vulnerability database
- If the retries did not succeed, call trivy with `--skip-db-update --skip-check-update` (not ideal but better than nothing)
- Bash/Perl: Support shell scripts with no extension and only support perl shebangs at the beginning of a file in <https://github.com/oxsecurity/megalinter/pull/4076>

- Fixes
- Add debug traces to investigate reporters activation
Expand Down
1 change: 1 addition & 0 deletions docs/descriptors/bash_shellcheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ This linter is available in the following flavors
### How are identified applicable files

- File extensions: `.sh`, `.bash`, `.dash`, `.ksh`
- Shebangs: `#!/usr/bin/env bash`, `#!/bin/bash`, `#!/bin/sh`

<!-- markdownlint-disable -->
<!-- /* cSpell:disable */ -->
Expand Down
7 changes: 7 additions & 0 deletions megalinter/descriptors/bash.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ descriptor_flavors:
- c_cpp
- formatters
file_extensions:
- ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the impact of this in projects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the file without an extension does not include a matching shebang, my understanding is that there will be no impact

Copy link
Contributor Author

@tnyeanderson tnyeanderson Oct 1, 2024

Choose a reason for hiding this comment

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

However, this is needed in order for the conditional logic to even reach the point where it checks for matches in file_contains_regex. reference

- ".sh"
- ".bash"
- ".dash"
- ".ksh"
file_contains_regex_extensions:
- ""
file_contains_regex:
- "^#!/usr/bin/env bash"
- "^#!/bin/bash"
- "^#!/bin/sh"
install:
apk:
- bash
Expand Down
4 changes: 2 additions & 2 deletions megalinter/descriptors/perl.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ file_extensions:
file_contains_regex_extensions:
- ""
file_contains_regex:
- "#!/usr/bin/env perl"
- "#!/usr/bin/perl"
- "^#!/usr/bin/env perl"
- "^#!/usr/bin/perl"
install:
apk:
- perl
Expand Down