rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Add a script for finding missing methods and aliases in an RBS.

Open connorshea opened this issue 5 years ago • 0 comments

I wrote a script to find methods and aliases that are missing from an RBS by using the runtime prototyper:

ruby-signature connorshea$ bundle exec bin/find_missing --patterns=Module stdlib/builtin/module.rbs
Opening stdlib/builtin/module.rbs...
Missing methods:
- const_source_location
- deprecate_constant
- pretty_print
- pretty_print_cycle
- undef_method
- initialize_clone
- initialize_copy
- method_undefined
- ruby2_keywords

Missing aliases:
- alias inspect to_s

I wanted to resolve #222 since it seemed like a decent way to determine where methods/aliases still needed signatures.

It can be used like so:

  • bundle exec bin/find_missing --patterns=Module stdlib/builtin/module.rbs
  • bundle exec bin/find_missing --patterns=Set stdlib/set/set.rbs
  • bundle exec bin/find_missing --patterns=Abbrev --require=abbrev stdlib/abbrev/abbrev.rbs

It's pretty hacky, and there are still some problems with it:

  • It lists methods that are mixed in from other classes/modules, like pretty_print.
  • The way it outputs the aliases and methods is not ideal, it should probably be done in a way that can be copy-pasted into the file.
  • It doesn't understand module_function methods (e.g. self?.foo), so it incorrectly marks some methods as missing when they shouldn't be.
  • It doesn't handle files with multiple classes/modules correctly right now.

The idea with this is that it'd be useful for finding methods that still need to be added to a class, e.g. Module#deprecate_constant isn't included in module.rbs.

Is there interest in merging this? I wanted to get feedback before continuing :)

connorshea avatar Mar 21 '20 21:03 connorshea