glam/.opencode/rules/linkml/no-rough-edits-in-schema.md
kempersc 554fe520ea Add comprehensive rules for LinkML schema management and ontology mapping
- Introduced Rule 42: No Ontology Prefixes in Slot Names to enforce clean naming conventions.
- Established Rule: No Rough Edits in Schema Files to ensure structural integrity during modifications.
- Implemented Rule: No Version Indicators in Names to maintain stable semantic naming.
- Created Rule: Ontology Detection vs Heuristics to emphasize the importance of verifying ontology definitions.
- Defined Rule 50: Ontology-to-LinkML Mapping Convention to standardize mapping practices.
- Added Rule: Polished Slot Storage Location to specify directory structure for polished slot files.
- Enforced Rule: Preserve Bespoke Slots Until Refactoring to prevent unintended migrations during slot updates.
- Instituted Rule 56: Semantic Consistency Over Simplicity to mandate execution of revisions in slot_fixes.yaml.
- Added new Genealogy Archives Registry Enrichment class with multilingual support and structured aliases.
2026-02-15 19:20:09 +01:00

1.8 KiB

Rule: No Rough Edits in Schema Files

Identifier: no-rough-edits-in-schema Severity: CRITICAL

Core Directive

DO NOT perform rough, imprecise, or bulk text substitutions (like sed -i or regex-based python scripts) on LinkML schema files (schemas/*/linkml/) without guaranteeing structural integrity.

YOU MUST:

  • Use proper YAML parsers/dumpers if modifying structure programmatically.
  • Manually verify edits if using text replacement.
  • Ensure indentation and nesting are preserved exactly.
  • Respect comments and ordering (which parsers often destroy, so careful text editing is sometimes necessary, but it must be PRECISE).

Rationale

LinkML schemas are highly structured YAML files where indentation and nesting semantics are critical. Rough edits often cause:

  • Duplicate keys (e.g., leaving a property behind after deleting its parent key).
  • Invalid indentation (breaking the parent-child relationship).
  • Silent corruption (valid YAML but wrong semantics).

Examples

Anti-Pattern: Rough Deletion

Deleting lines containing a string without checking context:

# WRONG: Deleting lines blindly
for line in lines:
    if "some_slot" in line:
        continue # Deletes the line, but might leave children orphaned!
    new_lines.append(line)

Resulting Corruption:

# Original
slots:
  some_slot:
    range: string

# Corrupted (orphaned child)
slots:
    range: string  # INVALID!

Correct Pattern: Structural Awareness

If removing a slot reference, ensure you remove the entire list item or key-value block.

# BETTER: Check for list item syntax
if re.match(r'^\s*-\s*some_slot\s*$', line):
    continue

Application

This rule applies to ALL files in schemas/20251121/linkml/ and future versions.