CruGlobal / bill-bucks-generator

Rails app for building and distributing Bill Bucks.
2 stars 0 forks source link

Add Sorbet for static type checking #21

Closed soberstadt closed 3 years ago

soberstadt commented 3 years ago

You should be able to run type checking yourself with bundle exec srb tc. I've also found this works really well with the sorbet-lsp extension (which I enable only in sorbet enabled workspaces).

Demo of sobert finding potential "undefined method on nil": image

soberstadt commented 3 years ago

@dbenton9 those are the cached definitions of all of our gem dependencies and rails stuff (routes and other dynamic things).

soberstadt commented 3 years ago

For future reference, we could if we wanted to define all the method signatures in external files, but I'm not sure I want to at this point:

# typed: strict

class Buck < ApplicationRecord
  sig {returns(T.nilable(String))}
  attr_accessor :dept

  sig {returns(String)}
  def to_blob; end

  sig {params(text: T.nilable(String), width: Integer).returns(String)}
  def fit_text(text, width); end

  private

  sig {returns(Magick::ImageList)}
  def build_image; end

  sig {returns(Magick::ImageList)}
  def bill_or_vonette; end

  sig {returns(Magick::Draw)}
  def text_instance; end

  sig {params(text: String, width: Integer).returns(T::Boolean)}
  def text_fit?(text, width); end
end