Skip to content

Conversation

@akonan
Copy link
Owner

@akonan akonan commented Nov 24, 2025

Summary

This PR implements the validation layer for the parsed AST as described in issue #16. The implementation provides comprehensive validation with clear, actionable error messages and full backward compatibility.

What's Included

  • ✅ Enhanced validation for all 40+ component types
  • ✅ Clear, actionable error messages with suggestions for fixes
  • ✅ Position tracking (line/column) when available
  • ✅ Nested structure validation rules
  • ✅ Comprehensive test coverage (17 new tests)
  • ✅ Full backward compatibility with existing validation

Key Features

1. Smart Error Messages

  • Suggests similar types when typos are detected (e.g., "buton" → "Did you mean: button?")
  • Provides helpful context (e.g., "Initialize with {} if no properties are needed")
  • Shows position information when available

2. Component Validation

  • Validates required properties for each component type
  • Checks property value enums (variants, input types, etc.)
  • Enforces nested structure rules (e.g., buttons can't contain buttons)

3. Accessibility & Best Practices

  • Tables should start with headers
  • Links shouldn't contain interactive elements
  • Radio groups enforce single selection

Usage

// Use original validation (default)
const errors = validate(ast);

// Use enhanced validation
const errors = validate(ast, { enhanced: true });

Test Plan

  • Run npm test - all 488 tests pass
  • Run npm run build - builds successfully
  • Test enhanced validation with various edge cases
  • Verify backward compatibility with existing code

Breaking Changes

None - the enhanced validation is opt-in via options parameter.

Related

🤖 Generated with Claude Code

akonan and others added 2 commits November 24, 2025 16:43
This commit implements a comprehensive validation layer for the wiremd AST
that provides:

- Clear, actionable error messages with suggestions for common mistakes
- Position tracking to show line/column information when available
- Comprehensive validation rules for all component types
- Nested structure validation (e.g., buttons can't contain buttons)
- Type-aware property validation (variants, input types, etc.)
- Backward compatible with existing validation function

The enhanced validation can be enabled by passing { enhanced: true } to
the validate() function. This addresses issue #16 requirements for better
validation and error reporting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use temp directory with unique filenames to avoid file conflicts
- Add existence check before file operations
- Handle Windows file system timing issues gracefully

This fixes the CI failure on Windows with Node 18.x where the test
was failing with ENOENT error when trying to read test-output.html.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add validation layer for parsed AST

2 participants