{"id":13411605,"url":"https://github.com/soutaro/steep","last_synced_at":"2025-05-14T22:06:59.108Z","repository":{"id":37774018,"uuid":"86352893","full_name":"soutaro/steep","owner":"soutaro","description":"Static type checker for Ruby","archived":false,"fork":false,"pushed_at":"2025-05-07T15:52:37.000Z","size":6368,"stargazers_count":1411,"open_issues_count":157,"forks_count":100,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-05-07T21:59:53.276Z","etag":null,"topics":["ruby","typechecker"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soutaro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-27T15:34:46.000Z","updated_at":"2025-05-07T15:52:41.000Z","dependencies_parsed_at":"2023-12-04T02:29:02.733Z","dependency_job_id":"f962997e-99ab-4096-8eb2-b633ec2d8c31","html_url":"https://github.com/soutaro/steep","commit_stats":{"total_commits":2438,"total_committers":47,"mean_commits":51.87234042553192,"dds":0.1591468416735029,"last_synced_commit":"723271091a7b096a9f682e8f002f75412831e3c1"},"previous_names":[],"tags_count":130,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fsteep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fsteep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fsteep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soutaro%2Fsteep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soutaro","download_url":"https://codeload.github.com/soutaro/steep/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235695,"owners_count":22036963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","typechecker"],"created_at":"2024-07-30T20:01:14.929Z","updated_at":"2025-05-14T22:06:54.072Z","avatar_url":"https://github.com/soutaro.png","language":"Ruby","readme":"# Steep - Gradual Typing for Ruby\n\n## Installation\n\nInstall via RubyGems.\n\n    $ gem install steep\n\n### Requirements\n\nSteep requires Ruby 2.6 or later.\n\n## Usage\n\nSteep does not infer types from Ruby programs, but requires declaring types and writing annotations.\nYou have to go on the following three steps.\n\n### 0. `steep init`\n\nRun `steep init` to generate a configuration file.\n\n```\n$ steep init       # Generates Steepfile\n```\n\nEdit the `Steepfile`:\n\n```rb\ntarget :app do\n  check \"lib\"\n  signature \"sig\"\n\n  library \"pathname\"\nend\n```\n\n### 1. Declare Types\n\nDeclare types in `.rbs` files in `sig` directory.\n\n```\nclass Person\n  @name: String\n  @contacts: Array[Email | Phone]\n\n  def initialize: (name: String) -\u003e untyped\n  def name: -\u003e String\n  def contacts: -\u003e Array[Email | Phone]\n  def guess_country: -\u003e (String | nil)\nend\n\nclass Email\n  @address: String\n\n  def initialize: (address: String) -\u003e untyped\n  def address: -\u003e String\nend\n\nclass Phone\n  @country: String\n  @number: String\n\n  def initialize: (country: String, number: String) -\u003e untyped\n  def country: -\u003e String\n  def number: -\u003e String\n\n  def self.countries: -\u003e Hash[String, String]\nend\n```\n\n* You can use simple *generics*, like `Hash[String, String]`.\n* You can use *union types*, like `Email | Phone`.\n* You have to declare not only public methods but also private methods and instance variables.\n* You can declare *singleton methods*, like `self.countries`.\n* There is `nil` type to represent *nullable* types.\n\n### 2. Write Ruby Code\n\nWrite Ruby code with annotations.\n\n```rb\nclass Person\n  # `@dynamic` annotation is to tell steep that\n  # the `name` and `contacts` methods are defined without def syntax.\n  # (Steep can skip checking if the methods are implemented.)\n\n  # @dynamic name, contacts\n  attr_reader :name\n  attr_reader :contacts\n\n  def initialize(name:)\n    @name = name\n    @contacts = []\n  end\n\n  def guess_country()\n    contacts.map do |contact|\n      # With case expression, simple type-case is implemented.\n      # `contact` has type of `Phone | Email` but in the `when` clause, contact has type of `Phone`.\n      case contact\n      when Phone\n        contact.country\n      end\n    end.compact.first\n  end\nend\n\nclass Email\n  # @dynamic address\n  attr_reader :address\n\n  def initialize(address:)\n    @address = address\n  end\n\n  def ==(other)\n    # `other` has type of `untyped`, which means type checking is skipped.\n    # No type errors can be detected in this method.\n    other.is_a?(self.class) \u0026\u0026 other.address == address\n  end\n\n  def hash\n    [self.class, address].hash\n  end\nend\n\nclass Phone\n  # @dynamic country, number\n  attr_reader :country, :number\n\n  def initialize(country:, number:)\n    @country = country\n    @number = number\n  end\n\n  def ==(other)\n    # You cannot use `case` for type case because `other` has type of `untyped`, not a union type.\n    # You have to explicitly declare the type of `other` in `if` expression.\n\n    if other.is_a?(Phone)\n      # @type var other: Phone\n      other.country == country \u0026\u0026 other.number == number\n    end\n  end\n\n  def hash\n    [self.class, country, number].hash\n  end\nend\n```\n\n### 3. Type Check\n\nRun `steep check` command to type check. 💡\n\n```\n$ steep check\nlib/phone.rb:46:0: MethodDefinitionMissing: module=::Phone, method=self.countries (class Phone)\n```\n\nYou now find `Phone.countries` method is not implemented yet. 🙃\n\n## Prototyping signature\n\nYou can use `rbs prototype` command to generate a signature declaration.\n\n```\n$ rbs prototype rb lib/person.rb lib/email.rb lib/phone.rb\nclass Person\n  @name: untyped\n  @contacts: Array[untyped]\n  def initialize: (name: untyped) -\u003e Array[untyped]\n  def guess_country: () -\u003e untyped\nend\n\nclass Email\n  @address: untyped\n  def initialize: (address: untyped) -\u003e untyped\n  def ==: (untyped) -\u003e untyped\n  def hash: () -\u003e untyped\nend\n\nclass Phone\n  @country: untyped\n  @number: untyped\n  def initialize: (country: untyped, number: untyped) -\u003e untyped\n  def ==: (untyped) -\u003e void\n  def hash: () -\u003e untyped\nend\n```\n\nIt prints all methods, classes, instance variables, and constants.\nIt can be a good starting point to writing signatures.\n\nBecause it just prints all `def`s, you may find some odd points:\n\n* The type of `initialize` in `Person` looks strange.\n* There are no `attr_reader` methods extracted.\n\nGenerally, these are by our design.\n\n`rbs prototype` offers options: `rbi` to generate prototype from Sorbet RBI and `runtime` to generate from runtime API.\n\n## Docs\n\nThere are some documents in the `manul` and `guide` directories.\n\n* [Guides](guides)\n* [Manual](manual)\n\nThe `doc` directory contains a few internal design docs.\n\n* [Internal docs](doc)\n\n## Examples\n\nYou can find examples in `smoke` directory.\n\n## IDEs\n\nSteep implements some of the Language Server Protocol features.\n- For **VSCode** please install [the plugin](https://github.com/soutaro/steep-vscode).\n- For **SublimeText** please install [LSP](https://github.com/sublimelsp/LSP) package and follow [instructions](https://lsp.sublimetext.io/language_servers/#steep).\n- For **Vim** or **Neovim** please install [ALE](https://github.com/dense-analysis/ale?tab=readme-ov-file#asynchronous-lint-engine). You may want to `let g:ale_ruby_steep_executable = 'bundle'` to use your bundled `steep` version.\n\nOther LSP supporting tools may work with Steep where it starts the server as `steep langserver`.\n\n## Rake Tasks\n\nSteep comes with a set of configurable Rake tasks.\n\n```ruby\n# Rakefile\n\nrequire \"steep/rake_task\"\nSteep::RakeTask.new do |t|\n  t.check.severity_level = :error\n  t.watch.verbose\nend\n\ntask default: [:steep]\n```\n\nUse `bundle exec rake -T` to see all available tasks.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/soutaro/steep.\n\n","funding_links":[],"categories":["Ruby","Programming Languages","Ruby Type Annotations / Signatures"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoutaro%2Fsteep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoutaro%2Fsteep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoutaro%2Fsteep/lists"}