kgiszczak / shale

Shale is a Ruby object mapper and serializer for JSON, YAML, TOML, CSV and XML. It allows you to parse JSON, YAML, TOML, CSV and XML data and convert it into Ruby data structures, as well as serialize data structures into JSON, YAML, TOML, CSV or XML.
https://shalerb.org/
MIT License
618 stars 19 forks source link

Add RBS type signature #38

Open sferik opened 1 month ago

sferik commented 1 month ago

First, thank you for creating this project! Shale is a very nicely designed library and I've enjoyed working with it.

My only feature request is for you to add an RBS type signature file (sig/shale.rbs) to this project. I type check my code with Steep and now that many of my classes inherit from Steep::Mapper, my type checker is throwing dozens of errors.

If you'd like to see an example, here is an .rbs file and Steepfile from one of my projects.

You may also find typeprof useful to generate RBS scaffolding.

kgiszczak commented 1 month ago

Would you be willing to take a stab at it? I'd gladly accept PR with this change. If not I'll try to add it myself, although it may take some time.

sferik commented 1 month ago

I forked this repo and created an rbs branch with two commits:

  1. Add Steep to typecheck
  2. Automatically generate RBS file using TypeProf

When I run bundle exec rake steep, it detects 245 problems in the auto-generated type signatures. I'm not sure I have the expertise in this library necessary to fix them, but I figured I would update this issue with the scaffolding I generated in case that inspires someone else to attempt to resolve these problems.

I believe the majority of these issues can be resolved by adding nil checks or specifying that the value will not be nil in the type signature.

kgiszczak commented 1 month ago

Thank you, that's a good start. I'll try to look into it and maybe add those type signatures when I have some time.