Rubocop::Ruby19
See the intro blog post!
This gem requires no other gems. It depends on rubocop
, but does not require 'rubocop'
.
Awareness of rubocop
‘s lack of SemVer adherence isn’t evenly dispersed in the Ruby community.
The Rubocop team has real reasons
for not following SemVer, but if you’ve
found this project their reasons likely weigh less, in your context (e.g. running rubocop
from command line), than
what brought you here.
The purpose of this gem is to constrain the rubocop
dependency of a project in
a SemVer compliant (Semantic Versioning) way that aligns with the the desired minimum
compatible/supported Ruby version.
Ruby Version Support Matrix
Adding this gem will facilitate the best practice of adding a ~>
version constrained rubocop
dependency, while
minimizing the risk of a rubocop minor / patch upgrade breaking the build. See the
official compatibility matrix for rubocop
.
rubocop-ruby1_9
(this gem) will install on any version of Ruby >= 1.9, can be used to analyze Ruby >= 1.8.7 code, but will not execute on Ruby 3.1.
- 🧊 - Install on Ruby “
- 🏃 - Will Execute on Ruby ”
- 🪷 - Will not execute correctly on Ruby “
- 🛠 - Lint code with Ruby ” syntax as the target
gem | 1.8.7 | 1.9.3 | 2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 2.6 | 2.7 | 3.0 | 3.1 | ruby-head | jruby-head |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
rubocop-ruby1_9 | 🛠 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | 🧊 🪷 | 🧊 🪷 |
rubocop-ruby2_0 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | 🧊 🪷 | 🧊 🪷 | ||
rubocop-ruby2_1 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | 🧊 🪷 | 🧊 🪷 | |||
rubocop-ruby2_2 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | 🧊 🪷 | 🧊 🪷 | 🧊 🪷 | ||||
rubocop-ruby2_3 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | 🧊 🪷 | 🧊 🪷 | |||||
rubocop-ruby2_4 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | 🧊 🪷 | 🧊 🪷 | ||||||
rubocop-ruby2_5 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | |||||||
rubocop-ruby2_6 | 🛠 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🪷 | |||||||
rubocop-ruby2_7 | 🛠 | 🛠 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | |||||||
rubocop-ruby3_0 | 🛠 | 🛠 | 🛠 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 | 🧊 🏃 | |||||||
rubocop-ruby3_1 | 🛠 | 🛠 | 🛠 | 🛠 | 🧊 🏃 🛠 | 🧊 🏃 | 🧊 🏃 |
📼 Supporting Ruby v1… in 2022?
Many gems, and many of those among the most popular gems in all of Ruby-land (e.g. rspec, os) still do not specify a required_ruby_version
, or they list it as >= 0
.
If those gems want to:
- follow semver, and
- deprecate old rubies, then
- they need to first figure out what version of Ruby is currently supported, and
- once having determined the oldest supported version, they may want to enforce that support via linting, hence this family of gems.
NOTE: Some gems, e.g. rspec, are intentionally supporting Ruby 1.8.7 in 2022!
If you think about the use case of RSpec a bit this makes sense, as it would be ideal for the community for RSpec to be the last gem to drop support for Ruby 1.8.7. I wrote a suite of RSpec extension gems, and I try to support the same versions of Ruby as RSpec does with my extensions.
This gem targets, and will run, on Ruby 1.9. RuboCop used to be able to analyze Ruby 1.8, and this gem makes use of that. If you are still supporting Ruby 1.8, see What about Ruby 1.8? further down the page, because we can help!
🗿 Stable
All releases of this gem are stable releases. The first version is 1.0.0
.
✨ Installation
Without bundler execute:
$ gem install
Add this line to your application’s Gemfile:
gem 'rubocop-ruby1_9', '~> 1.0', require: false
And then execute:
$ bundle
Or install it yourself as:
$ gem install rubocop-ruby1_9
🔧 Usage
The following is optional. We’ll discuss why you might want to do this after you see what it does.
Add to the top of your project’s .rubocop.yml
configuration file:
inherit_gem: rubocop-ruby1_9: rubocop.yml
This has the same effect as you declaring the following in your .rubocop.yml
:
# AllCops: # The sibling gems for newer versions of Ruby support the TargetRubyVersion directive as soon as RuboCop adds it. # TargetRubyVersion: 1.9 # The sibling gems for newer versions of Ruby support the NewCops directive as soon as RuboCop adds it. # NewCops: enable Style/BracesAroundHashParameters: Enabled: true EnforcedStyle: context_dependent Style/Encoding: Enabled: true EnforcedStyle: always Style/ExpandPathArguments: Enabled: false
Let’s talk about these settings.
TargetRubyVersion
Commented out! Setting does not exist in the very old version of rubocop that works with Ruby 1.9.
If you want to use this you’ll have to upgrade to Ruby >= 2.0 and use the appropriate sibling gem, e.g. rubocop-ruby2_0
.
NewCops: enable
Commented out! Setting does not exist in very old versions of rubocop that work with Ruby < 2.4.
If you want to use this you’ll have to upgrade to Ruby >= 2.4 and use the appropriate sibling gem, e.g. rubocop-ruby2_4
.
Style/BracesAroundHashParameters
In an effort to help users of this gem prepare their code for more modern Rubies it has been enabled and configured with coontext_dependent
as the closest parallel to what will work with Ruby 2.7+, and also retain compatibility with old Ruby.
See:
NOTE: This cop was removed from RuboCop as of 0.80.0, so if you are on modern RuboCop and reading this for some reason, you can’t use it.
Style/Encoding
The encoding comments can be removed once your project drops Ruby 1.9 support (and this gem!).
Whole file UTF-8 Encoding is default in Ruby 2+, so the Encoding comment is usually not needed there.
See:
What about Ruby 1.8!
RuboCop has never supported running on Ruby 1.8.7, but it did used to support analyzing it. To that end, there is a set of RuboCop rules you can use if your project still supports Ruby 1.8.
inherit_gem: rubocop-ruby1_9: rubocop-ruby1_8.yml
I won’t copy the set of rules here, but you can peruse them here. If the rules don’t fit exactly your needs, you can just copy them out to your own .rubocop.yml
config and modify!
Three different projects informed these Rubocop rules for 1.8.7.
- rubocop_187’s .rubocop-yml - because
rubocop_187
is a Rails app built to Ruby-1.8.7-ify code added to it. - rspec’s .rubocop-yml - because
rspec
still supports Ruby 1.8.7 - rspec-pending_for’s .rubocop.yml - because
rspec-pending_for
still supports Ruby 1.8.7
If you have suggestions for a rule that improves compatibility with Ruby forward from 1.9 or 1.8, please let us know!
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. 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.
⚡️ Contributing
See CONTRIBUTING.md
🌈 Contributors
Made with contributors-img.
📄 License
The gem is available as open source under the terms of
the MIT License .
See LICENSE for the official Copyright Notice.
Project Logos (rubocop-ruby3_1)
See docs/images/logo/README.txt
Organization Logo (rubocop-semver)
Author: Yusuf Evli
Source: Unsplash
License: Unsplash License
© Copyright
- Copyright © 2022 Peter H. Boling of Rails Bling
🤝 Code of Conduct
Everyone interacting in the Rubocop::Ruby19 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
📌 Versioning
This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as
bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be
immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new
major versions.
As a result of this policy, you can (and should) specify a dependency on this gem using
the Pessimistic Version Constraint with two digits of precision.
For example:
spec.add_dependency "rubocop-ruby1_9", "~> 1.0"