RuboCop Kanso (簡素)
RuboCop extension for writing clean, minimal Ruby code. Kanso (簡素) is a Japanese principle meaning simplicity through elimination of clutter.
Installation
Add this line to your application's Gemfile:
gem 'rubocop-kanso', require: falseAnd then execute:
bundle installOr install it yourself as:
gem install rubocop-kansoUsage
Add the following to your .rubocop.yml:
plugins:
- rubocop-kanso
# Optional: Configure the cops
Kanso/NoRailsHelperRequire:
Enabled: true
Kanso/NoRSpecDescribe:
Enabled: trueCops
Kanso/NoRailsHelperRequire
This cop disallows requiring rails_helper in spec files. Instead, configure your .rspec file in the project root with the following lines:
--require rails_helper
Bad:
require "rails_helper"Good:
Configure .rspec file:
--require rails_helper
And remove the require statement from your spec files.
Auto-correction: ✅ Supported (removes the require statement)
Kanso/NoRSpecDescribe
This cop enforces using describe instead of RSpec.describe for consistency.
Bad:
RSpec.describe MyClass do
# spec content
endGood:
describe MyClass do
# spec content
endAuto-correction: ✅ Supported
Development
After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rspec to run the tests.
Testing
Run the test suite with:
bundle exec rspecBuilding the Gem
To build the gem:
gem build rubocop-kanso.gemspecPublishing
To release a new version:
- Update the version number in
lib/rubocop/kanso/version.rb - Run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the.gemfile to rubygems.org
Or manually:
gem build rubocop-kanso.gemspec
gem push rubocop-kanso-1.x.x.gemContributing
Bug reports and pull requests are welcome on GitHub at https://github.com/egracens/rubocop-kanso.
License
The gem is available as open source under the terms of the Apache License 2.0.