Documentation Fixes: - README.md: Update test count from 59 to 63 (badge, features, test command) - README.md: Fix lint script references to actual npm scripts - CONTRIBUTING.md: Correct format script reference to npm run format:check - package.json: Remove non-existent yamllint script, split lint:markdown into check/fix variants Grammar Enhancements: - Add fExampleGroup and xExampleGroup to Context block variants - Regenerate parser with new grammar (63/63 tests passing, 100% success rate) Syntax Highlighting: - Add fExampleGroup and xExampleGroup to focused/skipped block highlights - Remove non-matching Data modifier tokens (:raw, :expand, #|) - Add "End" keyword as block terminator Memory File Corrections: - Remove incorrect merge_group trigger references - Remove pr-lint.yml workflow references (deleted in previous optimization) - Update test counts with timestamps (59→63, added 2025-12-11) - Update conflict count (13→5, optimized) Code Style: - Auto-format renovate.json and tree-sitter.json with prettier
4.6 KiB
Real-World ShellSpec Patterns Analysis
Based on analysis of 24 official ShellSpec example files from test/spec/, this document captures the comprehensive patterns discovered and how they've been integrated into the grammar.
Key Findings from Official Examples
1. Hook Statement Patterns
Discovery: ShellSpec uses both block-style hooks (with End) and statement-style hooks (without End)
Statement-style hooks (newly supported):
Before 'setup'- Single function callBefore 'setup1' 'setup2'- Multiple function callsAfter 'cleanup'- Cleanup functionsBefore 'value=10'- Inline code execution
Grammar Implementation: Added shellspec_hook_statement rule to handle Before/After statements without End blocks.
2. Directive Patterns
Discovery: ShellSpec has several directive-style statements that don't follow the typical block structure
Include directive:
Include ./lib.sh- Include external scriptsInclude ./support/custom_matcher.sh
Conditional Skip:
Skip if "reason" condition- Skip with conditionsSkip if 'function returns "skip"' [ "$(conditions)" = "skip" ]- Complex conditions
Grammar Implementation: Added shellspec_directive_statement rule for Include and conditional Skip patterns.
3. Data Block Complexity (Future Enhancement)
Discovery: Data blocks have sophisticated syntax not yet fully supported:
Data:rawandData:expandmodifiers for variable expansion controlData | filtersyntax for piping data through filters#|contentline prefix syntax for multi-line data- Function-based data:
Data function_name - String-based data:
Data 'string content'
Current Status: Basic Data blocks work as utility blocks, but advanced syntax requires future enhancement.
4. Top-Level Examples
Discovery: ShellSpec allows It/Example/Specify blocks at the top level without requiring Describe/Context wrapping.
Pattern:
It 'is simple'
When call echo 'ok'
The output should eq 'ok'
End
Grammar Implementation: Already supported through existing shellspec_it_block rule.
5. Complex Nesting and Context Switching
Discovery: Real-world examples show sophisticated nesting:
- Describe > Context > It hierarchies
- Mixed hook scoping (hooks defined at different nesting levels)
- Before/After hooks with multiple arguments for setup chains
- Comments and shellcheck directives intermixed
Grammar Enhancements Made
New Rules Added
shellspec_hook_statement- For Before/After without Endshellspec_directive_statement- For Include and conditional Skip- Enhanced conflicts array to handle new statement types
Test Coverage Added
- 63 total tests (as of 2025-12-11; originally 59, up from 53)
- New
real_world_patterns.txttest file - 6 additional tests covering hook statements, directives, and complex patterns
- 4 additional tests for Data block modifiers (added 2025-12-11)
Integration Status
✅ Fully Integrated:
- Hook statements (Before/After without End)
- Include directive
- Conditional Skip statements
- Top-level It blocks
⚠️ Partially Supported:
- Data blocks (basic functionality works, advanced syntax needs work)
- Complex conditional expressions in Skip
🔄 Future Enhancements Needed:
- Data block modifiers (:raw, :expand)
- Data block filters (| syntax)
- Data block #| line syntax
- More sophisticated conditional parsing for Skip
Real-World Usage Patterns Observed
- Hook Chains: Multiple Before/After hooks for complex setup/teardown
- Conditional Logic: Heavy use of conditional Skip statements
- External Dependencies: Frequent use of Include for modular test organization
- Mixed Context: ShellSpec blocks mixed with regular bash functions and variables
- Assertion Patterns: Consistent use of When/The assertion syntax
- Descriptive Strings: Heavy use of descriptive string literals for test names
Grammar Statistics
- Block types: 5 (Describe, Context, It, Hook, Utility)
- Statement types: 2 (Hook statements, Directives)
- Keywords supported: 25+ ShellSpec keywords
- Test coverage: 100% (63/63 tests passing as of 2025-12-11)
- Conflict warnings: 5 (optimized from 13, all necessary)
Recommendations for Future Development
- Priority 1: Implement advanced Data block syntax for better real-world compatibility
- Priority 2: Enhance conditional Skip parsing to handle complex bash expressions
- Priority 3: Optimize conflict declarations to reduce parser warnings
- Priority 4: Add support for ShellSpec assertion syntax (When/The statements)