import os
import re
from typing import List, Tuple
def find_angular_files(root_dir: str) -> List[str]:
"""Find all HTML and TypeScript files in the Angular project."""
angular_files = []
for root, _, files in os.walk(root_dir):
for file in files:
if file.endswith(('.html', '.ts')):
angular_files.append(os.path.join(root, file))
return angular_files
def check_img_tags(file_path: str) -> List[Tuple[int, str]]:
"""Check for img tags without alt attribute in a file."""
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Regular expression to find <img> tags without alt attribute
img_pattern = re.compile(r'<img(?![^>]*alt=)[^>]*>', re.IGNORECASE)
issues = []
for match in img_pattern.finditer(content):
line_number = content[:match.start()].count('\n') + 1
issues.append((line_number, match.group()))
return issues
def main():
project_root = input("Enter the root directory of your Angular project: ")
if not os.path.isdir(project_root):
print(f"Error: {project_root} is not a valid directory.")
return
angular_files = find_angular_files(project_root)
for file_path in angular_files:
issues = check_img_tags(file_path)
if issues:
print(f"\nIssues found in {file_path}:")
for line_number, img_tag in issues:
print(f" Line {line_number}: {img_tag}")
if __name__ == "__main__":
main()