From 04a567519f88e37773fd37a9388966aebb6780b8 Mon Sep 17 00:00:00 2001 From: Mohamed Elashri Date: Fri, 15 Nov 2024 20:59:18 -0500 Subject: [PATCH] Fix: Ensure awesome-lint compliance with badge and punctuation updates --- generate_readme.py | 57 ++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/generate_readme.py b/generate_readme.py index 12c6b88..5046515 100755 --- a/generate_readme.py +++ b/generate_readme.py @@ -9,6 +9,7 @@ def extract_repo(url): match = re.match(r'https://github\.com/([^/]+/[^/]+)', url) return match[1] if match else '' + def add_badges(lines): """Add GitHub badges to lines containing GitHub repository URLs.""" processed_lines = [] @@ -22,11 +23,11 @@ def add_badges(lines): processed_lines.append('') # Add a blank line # Add shields.io badges badges = [ - f' ![Last Commit](https://img.shields.io/github/last-commit/{repo_name})', - f'![License](https://img.shields.io/github/license/{repo_name})', - f'![Issues](https://img.shields.io/github/issues/{repo_name})', - f'![Stars](https://img.shields.io/github/stars/{repo_name})', - f'![Forks](https://img.shields.io/github/forks/{repo_name})', + f' ![Last Commit](https://img.shields.io/github/last-commit/{repo_name}?style=flat-square)', + f'![License](https://img.shields.io/github/license/{repo_name}?style=flat-square)', + f'![Issues](https://img.shields.io/github/issues/{repo_name}?style=flat-square)', + f'![Stars](https://img.shields.io/github/stars/{repo_name}?style=flat-square)', + f'![Forks](https://img.shields.io/github/forks/{repo_name}?style=flat-square)', '' ] processed_lines.extend(badges) @@ -36,30 +37,35 @@ def add_badges(lines): processed_lines.append(line) return processed_lines -def style_badges(lines): - """Add the 'flat-square' style to all image badges in the lines.""" - def replace_style(match): - alt_text = match.group(1) - url = match.group(2) - url += '&style=flat-square' if '?' in url else '?style=flat-square' - return f'![{alt_text}]({url})' - styled_lines = [] - pattern = re.compile(r'!\[([^\]]+)\]\(([^)]+)\)') +def ensure_punctuation(lines): + """Ensure all list item descriptions end with a period.""" + punctuated_lines = [] for line in lines: - styled_line = pattern.sub(replace_style, line) - styled_lines.append(styled_line) - return styled_lines + # Match lines that start with list items and have descriptions + if re.match(r'- \[.*?\]\(.*?\) - .*[^.]$', line): + line += '.' # Append a period + punctuated_lines.append(line) + return punctuated_lines + def remove_extra_parentheses(lines): """Remove extra closing parentheses at the end of image markdown links.""" corrected_lines = [] for line in lines: - # Match image links with potential extra closing parentheses corrected_line = re.sub(r'(!\[[^\]]*\]\([^\)]*\))\)+', r'\1', line) corrected_lines.append(corrected_line) return corrected_lines + +def add_awesome_badge(lines): + """Ensure the Awesome badge is correctly added.""" + badge = '[![Awesome](https://awesome.re/badge-flat.svg)](https://awesome.re)' + if lines and badge not in lines[0]: + lines.insert(0, badge) + return lines + + def main(): if len(sys.argv) != 2: print("Usage: python script.py ") @@ -70,13 +76,14 @@ def main(): with open(input_file, 'r', encoding='utf-8') as f: lines = [line.rstrip('\n') for line in f] - lines_with_badges = add_badges(lines) + lines = add_awesome_badge(lines) + lines = add_badges(lines) + lines = ensure_punctuation(lines) + lines = remove_extra_parentheses(lines) - lines_with_square_badges = style_badges(lines_with_badges) - - final_lines = remove_extra_parentheses(lines_with_square_badges) - - for line in final_lines: + for line in lines: print(line) -main() + +if __name__ == "__main__": + main()