8000 fix: ignore non-executable files in `check_shellscript_set_options.py` by lukasoyen · Pull Request #98 · luminartech/dev-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

lukasoyen
Copy link
Contributor

No description provided.

@lukasoyen lukasoyen requested review from hofbi and cbachhuber April 25, 2025 09:57
@lukasoyen lukasoyen merged commit 915de41 into master Apr 25, 2025
7 checks passed
@lukasoyen lukasoyen deleted the fix-check_shellscript_set_options branch April 25, 2025 10:02
@@ -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)
Copy link
Collaborator

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

Suggested change
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

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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?

Copy link
Collaborator

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

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
0