-
Notifications
You must be signed in to change notification settings - Fork 1
fix: ignore non-executable files in check_shellscript_set_options.py
#98
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
Conversation
@@ -55,8 +65,8 @@ def _are_shell_files_valid(shell_files: list[Path], expected_options: str) -> bo | |||
def main(argv: Sequence[str] | None = None) -> int: | |||
args = parse_arguments(argv) | |||
|
|||
bash_files, sh_files = _separate_bash_from_sh_files(args.filenames) | |||
are_all_files_valid = _are_shell_files_valid(bash_files, "set -euxo pipefail") | |||
are_all_files_valid, bash_files, sh_files = _separate_bash_from_sh_files(args.filenames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of extending the separation function which should be only about separation, I would suggest to do the filtering here first
are_all_files_valid, bash_files, sh_files = _separate_bash_from_sh_files(args.filenames) | |
executable_files = [filename for filename in args.filenames if _is_executable(filename)] | |
are_all_files_valid, bash_files, sh_files = _separate_bash_from_sh_files(executable_files) |
If you want to unit test this, you could also move the list comprehension into a small function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbachhuber I was too slow, but could be a follow up PR. I still think that separation and executable filtering are 2 different tasks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is more intricate. We ultimately want to find out if the script is bash
or sh
. But we don't necessarily care about if it is executable or has a shebang. We only use the shebang to determine the language.
So if we now filter executable first, we would filter out files that are non-executable, but have a shebang and would have been flagged before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But scripts that are not executable could be considered as "libraries" and don't need a shebang
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we still want the set ...
for them right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they are considered as libraries I think they get what the executing script defines
No description provided.