Skip to content

Commit

Permalink
Improve target module validation
Browse files Browse the repository at this point in the history
  • Loading branch information
m417z committed Aug 17, 2024
1 parent f463da2 commit e323476
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions .github/pr_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ def get_target_modules_from_previous_line(previous_line: str):
if comment == '':
return []

return [x.strip() for x in comment.split(',')]
names = [x.strip() for x in comment.split(',')]
if not all(x.endswith('.dll') or x.endswith('.exe') for x in names):
return []

return names


def validate_symbol_hooks(path: Path):
Expand All @@ -270,21 +274,16 @@ def validate_symbol_hooks(path: Path):
line_num = 1 + mod_source[: match.start()].count('\n')

target_from_name = get_target_module_from_symbol_block_name(symbol_block_name)
target_from_name_valid = target_from_name and is_existing_windows_file_name(
target_from_name
)

previous_line = mod_source_lines[line_num - 2]
targets_from_comment = get_target_modules_from_previous_line(previous_line)
targets_from_comment_valid = targets_from_comment and all(
is_existing_windows_file_name(x) for x in targets_from_comment
)

if target_from_name_valid and targets_from_comment_valid:
warning_msg = 'Use either a comment or a variable name, not both.'
if target_from_name and targets_from_comment:
warning_msg = (
'Use either a comment or a variable name, not both. For example, you'
' can rename the variable from "user32DllHooks" to "user32Hooks".'
)
warnings += add_warning(path, line_num - 1, warning_msg)
elif target_from_name_valid or targets_from_comment_valid:
continue
elif target_from_name or targets_from_comment:
if target_from_name and not is_existing_windows_file_name(target_from_name):
warning_msg = (
Expand Down

0 comments on commit e323476

Please sign in to comment.