Created
January 8, 2026 10:01
-
-
Save jalotra/1fc73550d7b4b15f41fb578e92004788 to your computer and use it in GitHub Desktop.
This is a quick script to make your code not have AI slop : (emojis); senior devs hate those; so remove them before you raise a PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import argparse | |
| import re | |
| import sys | |
| from pathlib import Path | |
| def remove_emoji(string: str) -> str: | |
| emoji_pattern = re.compile( | |
| "[" | |
| "\U0001f600-\U0001f64f" | |
| "\U0001f300-\U0001f5ff" | |
| "\U0001f680-\U0001f6ff" | |
| "\U0001f1e0-\U0001f1ff" | |
| "\U00002500-\U00002bef" | |
| "\U00002702-\U000027b0" | |
| "\U00002702-\U000027b0" | |
| "\U000024c2-\U0001f251" | |
| "\U0001f926-\U0001f937" | |
| "\U00010000-\U0010ffff" | |
| "\u2640-\u2642" | |
| "\u2600-\u2b55" | |
| "\u200d" | |
| "\u23cf" | |
| "\u23e9" | |
| "\u231a" | |
| "\ufe0f" | |
| "\u3030" | |
| "]+", | |
| flags=re.UNICODE, | |
| ) | |
| return emoji_pattern.sub(r"", string) | |
| def process_file(path: Path, inplace: bool, dry_run: bool) -> bool: | |
| try: | |
| original = path.read_text(encoding="utf-8") | |
| except UnicodeDecodeError: | |
| print(f"[SKIP] {path} (not a text file)", file=sys.stderr) | |
| return False | |
| except Exception as e: | |
| print(f"[ERROR] {path}: {e}", file=sys.stderr) | |
| return False | |
| cleaned = remove_emoji(original) | |
| if original == cleaned: | |
| print(f"[UNCHANGED] {path}", file=sys.stderr) | |
| return False | |
| if dry_run: | |
| print(f"[DRY-RUN] {path} would be modified", file=sys.stderr) | |
| return True | |
| if inplace: | |
| path.write_text(cleaned, encoding="utf-8") | |
| print(f"[MODIFIED] {path}", file=sys.stderr) | |
| else: | |
| print(cleaned) | |
| return True | |
| def collect_files(paths: list, recursive: bool) -> list: | |
| files = [] | |
| for p in paths: | |
| path = Path(p) | |
| if path.is_file(): | |
| files.append(path) | |
| elif path.is_dir(): | |
| stack = [path] | |
| while stack: | |
| current = stack.pop() | |
| for child in current.iterdir(): | |
| if child.is_file(): | |
| files.append(child) | |
| elif child.is_dir() and recursive: | |
| stack.append(child) | |
| else: | |
| print(f"[WARN] {p} does not exist", file=sys.stderr) | |
| return files | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser( | |
| description="Remove emojis from files", | |
| formatter_class=argparse.RawDescriptionHelpFormatter, | |
| epilog=""" | |
| Examples: | |
| %(prog)s file.txt # Output cleaned content to stdout | |
| %(prog)s file.txt --inplace # Modify file in place | |
| %(prog)s file.txt --dry-run # Preview which files would be modified | |
| %(prog)s ./docs --recursive --inplace # Process all files in directory recursively | |
| %(prog)s *.md --inplace # Process all markdown files in current dir | |
| """, | |
| ) | |
| parser.add_argument("files", nargs="+", help="Files or directories to process") | |
| parser.add_argument( | |
| "-r", "--recursive", action="store_true", help="Recursively process directories" | |
| ) | |
| mode_group = parser.add_mutually_exclusive_group() | |
| mode_group.add_argument( | |
| "-i", "--inplace", action="store_true", help="Modify files in place" | |
| ) | |
| mode_group.add_argument( | |
| "-n", | |
| "--dry-run", | |
| action="store_true", | |
| help="Show which files would be modified without making changes", | |
| ) | |
| args = parser.parse_args() | |
| files = collect_files(args.files, args.recursive) | |
| if not files: | |
| print("No files found to process", file=sys.stderr) | |
| sys.exit(1) | |
| print(f"Processing {len(files)} file(s)...\n", file=sys.stderr) | |
| modified_count = 0 | |
| for f in files: | |
| if process_file(f, args.inplace, args.dry_run): | |
| modified_count += 1 | |
| print( | |
| f"\nDone. {modified_count}/{len(files)} file(s) {'would be ' if args.dry_run else ''}modified.", | |
| file=sys.stderr, | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment