|
| 1 | +# RBS Type Signatures |
| 2 | + |
| 3 | +This directory contains [RBS](https://github.com/ruby/rbs) type signatures for the zxcvbn-ruby gem. |
| 4 | + |
| 5 | +## What is RBS? |
| 6 | + |
| 7 | +RBS is Ruby's type signature language. It provides a way to describe the structure of Ruby programs with: |
| 8 | +- Class and module definitions |
| 9 | +- Method signatures with parameter and return types |
| 10 | +- Instance variables and constants |
| 11 | +- Duck typing and union types |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### Validating Type Signatures |
| 16 | + |
| 17 | +To validate that the RBS files are syntactically correct: |
| 18 | + |
| 19 | +```bash |
| 20 | +bundle exec rake rbs:validate |
| 21 | +``` |
| 22 | + |
| 23 | +### Runtime Type Checking |
| 24 | + |
| 25 | +To run runtime type checking against the actual Ruby code during tests: |
| 26 | + |
| 27 | +```bash |
| 28 | +bundle exec rake rbs:test |
| 29 | +``` |
| 30 | + |
| 31 | +This runs the RSpec test suite with RBS type checking enabled, verifying that method calls match their type signatures at runtime. Note: This takes about 2 minutes to run. |
| 32 | + |
| 33 | +### Other Useful Commands |
| 34 | + |
| 35 | +List all Zxcvbn types: |
| 36 | +```bash |
| 37 | +bundle exec rake rbs:list |
| 38 | +``` |
| 39 | + |
| 40 | +Check syntax of RBS files: |
| 41 | +```bash |
| 42 | +bundle exec rake rbs:parse |
| 43 | +``` |
| 44 | + |
| 45 | +## File Structure |
| 46 | + |
| 47 | +The signatures mirror the structure of the `lib/` directory: |
| 48 | + |
| 49 | +- `sig/zxcvbn.rbs` - Main Zxcvbn module |
| 50 | +- `sig/zxcvbn/*.rbs` - Core classes (Tester, Score, Match, etc.) |
| 51 | +- `sig/zxcvbn/matchers/*.rbs` - Pattern matcher classes |
| 52 | + |
| 53 | +## Adding New Signatures |
| 54 | + |
| 55 | +When adding new classes or methods to the codebase, remember to: |
| 56 | + |
| 57 | +1. Create or update the corresponding `.rbs` file in the `sig/` directory |
| 58 | +2. Run `bundle exec rake rbs_validate` to ensure the syntax is correct |
| 59 | +3. Keep type signatures in sync with the actual implementation |
| 60 | + |
| 61 | +## Resources |
| 62 | + |
| 63 | +- [RBS Documentation](https://github.com/ruby/rbs) |
| 64 | +- [RBS Syntax Guide](https://github.com/ruby/rbs/blob/master/docs/syntax.md) |
| 65 | +- [Ruby Signature Collection](https://github.com/ruby/gem_rbs_collection) |
0 commit comments