scripts-fix-md029-ordered-list-prefix
#!/usr/bin/env python3 """
title: "MD029: Ordered list item prefix (consistent numbering)" component_type: script version: "1.0.0" audience: contributor status: stable summary: "CODITECT Markdown Quality System Copyright © 2025 AZ1.AI INC - All Rights Reserved" keywords: ['fix', 'list', 'md029', 'ordered', 'prefix'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "fix-md029-ordered-list-prefix.py" language: python executable: true usage: "python3 scripts/fix-md029-ordered-list-prefix.py [options]" python_version: "3.10+" dependencies: [] modifies_files: false network_access: false requires_auth: false
CODITECT Markdown Quality System Copyright © 2025 AZ1.AI INC - All Rights Reserved
This software is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited.
CODITECT owns all intellectual property rights to this implementation. """
MD029: Ordered list item prefix (consistent numbering)
import re from pathlib import Path
def fix_md029(content): """Ensure ordered lists use consistent sequential numbering.""" lines = content.split('\n') result = [] fixed = 0 in_list = False list_number = 1
for line in lines:
if match := re.match(r'^(\s*)(\d+)\.\s+(.+)', line):
indent, _, text = match.groups()
if not in_list:
in_list = True
list_number = 1
correct_line = f"{indent}{list_number}. {text}"
if line != correct_line:
result.append(correct_line)
fixed += 1
else:
result.append(line)
list_number += 1
else:
if in_list and line.strip():
in_list = False
list_number = 1
result.append(line)
return '\n'.join(result), fixed
def process_file(file_path, dry_run=False): try: with open(file_path, 'r', encoding='utf-8') as f: content = f.read() fixed_content, count = fix_md029(content) if count > 0 and not dry_run: with open(file_path, 'w', encoding='utf-8') as f: f.write(fixed_content) return count except Exception as e: print(f"Error: {e}") return 0
if name == 'main': import argparse parser = argparse.ArgumentParser(description='Fix MD029: Ordered list numbering') parser.add_argument('paths', nargs='*', default=['.']) parser.add_argument('--dry-run', action='store_true') args = parser.parse_args()
total = 0
for path_str in args.paths:
path = Path(path_str)
if path.is_file() and path.suffix == '.md':
# Process single file
count = process_file(path, args.dry_run)
if count:
print(f"{'[DRY RUN] ' if args.dry_run else ''}Fixed {count} issues in {path}")
total += count
elif path.is_dir():
# Process directory
for md_file in path.rglob('*.md'):
count = process_file(md_file, args.dry_run)
if count:
print(f"{'[DRY RUN] ' if args.dry_run else ''}Fixed {count} issues in {md_file}")
total += count
print(f"\nTotal: {total} issues fixed")