Sorbet usage: Difference between revisions

From wikinotes
(Created page with " * sorbet-runtime runs with your code * sorbet-static reads your code without evaluating it = Commandline = <blockquote> Static typechecking <source lang="bash"> bundle exec srb tc --help 2>&1 | less -Ri # show help in less bundle exec srb tc 2>&1 | grep -C5 ClassICareAbout # check for errors in specific class </source> </blockquote><!-- Commandline --> = Code = <blockquote> Within your code, syntax is provided by <code>sorbet-runtime</code>. <syntaxhighlig...")
 
No edit summary
 
Line 2: Line 2:
* sorbet-runtime runs with your code
* sorbet-runtime runs with your code
* sorbet-static reads your code without evaluating it
* sorbet-static reads your code without evaluating it
= Install =
<blockquote>
<syntaxhighlight lang="bash">
gem install sorbet        # install srb
gem install sorbet-runtime # sorbet runtime checks
gem install sorbet-static  # sorbet static checks
</syntaxhighlight>
</blockquote><!-- Install -->


= Commandline =
= Commandline =

Latest revision as of 19:26, 4 November 2023

  • sorbet-runtime runs with your code
  • sorbet-static reads your code without evaluating it

Install

gem install sorbet         # install srb
gem install sorbet-runtime # sorbet runtime checks
gem install sorbet-static  # sorbet static checks

Commandline

Static typechecking

bundle exec srb tc --help 2>&1 | less -Ri           # show help in less
bundle exec srb tc 2>&1 | grep -C5 ClassICareAbout  # check for errors in specific class

Code

Within your code, syntax is provided by sorbet-runtime.

require "sorbet-runtime"

class Foo
    extend T::Sig

    sig { params(a: String, b: T.nilable(Integer)).void }
    def bar(a, b: nil) = nil
end

Language Server Protocol (LSP)

You can also use sorbet as an LSP.

srb tc --lsp