- Add full ShellSpec grammar extending tree-sitter-bash - Support all ShellSpec constructs: Describe, Context, It, hooks, utilities - Include Data block parsing with statements and argument styles - Add 61 comprehensive test cases covering real-world patterns - Implement optimized GitHub workflows with CI/CD automation - Configure complete development tooling (linting, formatting, pre-commit) - Add comprehensive documentation and contribution guidelines - Optimize grammar conflicts to zero warnings - Support editor integration for Neovim, VS Code, Emacs Breaking Changes: - Initial release, no previous API to break BREAKING CHANGE: Initial implementation of tree-sitter-shellspec grammar # Conflicts: # .github/workflows/codeql.yml # .github/workflows/pr-lint.yml # .pre-commit-config.yaml # Conflicts: # .github/workflows/pr-lint.yml # Conflicts: # .github/workflows/pr-lint.yml
4.5 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
- 59 total tests (up from 53)
- New
real_world_patterns.txttest file - 6 additional tests covering hook statements, directives, and complex patterns
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% (59/59 tests passing)
- Conflict warnings: 13 (mostly unnecessary, can be optimized)
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)