Skip to content

Conversation

@orien
Copy link
Member

@orien orien commented Jan 15, 2026

Context

This PR introduces RBS (Ruby Signature) type definitions for the entire public API and internal classes. RBS provides optional static type checking for Ruby, enabling better IDE support, earlier error detection, and improved documentation for gem users.

Changes

  • Add comprehensive RBS signatures for all core classes (Zxcvbn, Tester, Score, Match, Feedback, etc.)
  • Add rake tasks for type validation and testing:
    • rake rbs:validate - Validate type signature correctness
    • rake rbs:test - Run runtime type checking against test suite
    • rake rbs:list - List all defined types
    • rake rbs:parse - Check RBS syntax
  • Update CI pipeline to validate RBS signatures on every commit
  • Configure rbs_collection.yaml for dependency type signatures
  • Update gemspec to exclude development-only RBS configuration from gem package
  • Add sig/README.md with usage instructions and examples

All type signatures have been validated through runtime type checking using rbs test against the full RSpec test suite (291 examples, 0 failures).

Considerations

  • RBS signatures are included in the published gem, adding approximately 15 files to the package
  • The signatures use Numeric instead of Float where methods return both integers and floats
  • Some parameters accept untyped arrays where the implementation performs sanitisation
  • Runtime type checking (rbs:test) takes approximately 2 minutes and is not included in the default rake task

orien added 2 commits January 15, 2026 12:22
Introduces comprehensive RBS type signatures for the entire public API
and internal classes. This provides improved type checking, better IDE
support, and documentation for gem users.

All type signatures have been validated through runtime type checking
using `rbs test` against the full RSpec test suite (291 examples, 0 failures).

Changes:
- Add RBS signatures for all core classes (Zxcvbn, Tester, Score, Match, etc.)
- Add rake tasks for RBS validation and testing (rbs:validate, rbs:test, rbs:list, rbs:parse)
- Configure rbs_collection.yaml for dependency type signatures
- Update gemspec to exclude rbs_collection.yaml from gem package
- Add sig/README.md with usage instructions
- Fix type signatures based on runtime validation:
  - Use Numeric instead of Float for entropy calculations (handles both Integer and Float)
  - Accept nullable parameters where nil is valid (password, Match in year_entropy)
  - Support Symbol keys in DictionaryRanker for test compatibility
  - Allow untyped arrays in user_inputs for proper sanitization
@orien orien merged commit e4d46ec into master Jan 15, 2026
22 checks passed
@orien orien deleted the rbs branch January 15, 2026 05:28
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.

2 participants