A RuboCop extension focused on enforcing RBS best practices and coding conventions.
Now, We can support RBS files by rubocop.
$ cat sig/foo.rbs
module Foo
def foo: ( void) -> untyped
end
$ bundle exec rubocop sig/foo.rbs
Inspecting 1 file
W
Offenses:
sig/foo.rbs:2:1: C: [Correctable] RBS/Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
def foo: ( void) -> untyped
sig/foo.rbs:2:11: C: [Correctable] RBS/Layout/ExtraSpacing: Unnecessary spacing detected.
def foo: ( void) -> untyped
^^
sig/foo.rbs:2:14: W: RBS/Lint/WillSyntaxError: void type is only allowed in return type or generics parameter
def foo: ( void) -> untyped
^^^^
1 file inspected, 3 offenses detected, 2 offenses autocorrectable
We are currently working on a response, but it is possible to modify part of vscode-rubocop as a temporary hack to use it in vscode as well.
Open your installed vscode extension.
$ code ~/.vscode/extensions/rubocop.vscode-rubocop-X.Y.Z/
Search documentSelector:[{
.
Then, Edit to add following to documentSelector[]
{scheme:"file",language:"rbs"}
Additionally, by configuring the settings.json
below, you can enable auto-correction to run on file save.
{
"[rbs]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "rubocop.vscode-rubocop"
},
}
And restart VSCode.
You can see documentation for all cops.
https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages/cops.adoc
This gem handles many cops. All cops can be enabled by following setting by default.
RBS:
Enabled: true
This department is a collection of relatively minor fixes has been gathered.
RBS/Layout:
Enabled: true
$ bundle exec rubocop --only RBS/Layout
This department is gathering important points that need to be fixed.
RBS/Lint:
Enabled: true
$ bundle exec rubocop --only RBS/Lint
This department unifies multiple styles.
RBS/Style:
Enabled: true
$ bundle exec rubocop --only RBS/Style
Install the gem and add to the application's Gemfile by executing:
$ bundle add rubocop-on-rbs --require false
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install rubocop-on-rbs
You need to tell RuboCop to load the RBS extension. There are three ways to do this:
Put this into your .rubocop.yml
.
require: rubocop-on-rbs
Alternatively, use the following array notation when specifying multiple extensions.
require:
- rubocop-other-extension
- rubocop-on-rbs
Now you can run rubocop
and it will automatically load the RuboCop on RBS
cops together with the standard cops.
$ rubocop --require rubocop-on-rbs
require 'rubocop/rake_task'
RuboCop::RakeTask.new do |task|
task.requires << 'rubocop-on-rbs'
end
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To 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 the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/ksss/rubocop-on-rbs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the RuboCop on RBS project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.