Skip to content

rubocop-lts/rubocop-ruby3_1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SVG RuboCop Logo, Copyright (c) 2014 Dimiter Petrov, CC BY-NC 4.0, see docs/images/logo/README.txt SVG RuboCop Logo, Copyright (c) 2014 Dimiter Petrov, CC BY-NC 4.0, see docs/images/logo/README.txt Yukihiro Matsumoto, Ruby Visual Identity Team, CC BY-SA 2.5, see docs/images/logo/README.txt SemVer.org Logo by @maxhaz, see docs/images/logo/README.txt SemVer.org Logo by @maxhaz, see docs/images/logo/README.txt

🦾 Rubocop::Ruby31

πŸ’‘ See the intro blog post!


The RuboCop LTS family of gems is the distillation of almost 20 years of my own Ruby expertise and source code diving, built on the shoulders of the expertise of many others; organizing that expertise into per-Ruby-version sets of configurations.

Although the situation has improved somewhat, it remains unsafe to upgrade RuboCop, or Standard, in a project that supports EOL Rubies.

I hope it helps others avoid some of the challenges I've had with library maintenance, and supporting decade-old mission-critical applications.

Avoid bike-shedding, use rubocop-lts in every project, and let it manage your linting complexity!

If the rubocop-lts stack of libraries has helped you, or your organization, please support my efforts by making a donation, or becoming a sponsor.

Liberapay Patrons Sponsor Me on Github

Buy me coffee donation button Patreon donate button

NOTE: You might be interested in rubocop-lts which sits as a higher level than this gem, and can keep pace with whatever version of Ruby you happen to be on.

Gem Name Version Downloads CI Activity
rubocop-lts Gem Version Total DL DL Rank Current Open Issues Closed Issues Open PRs Closed PRs
rubocop-ruby3_1 Gem Version Total DL DL Rank Current Heads Open Issues Closed Issues Open PRs Closed PRs

This gem configures many gems for you, and configures all of them for a specific version of Ruby:

  • rubocop
  • rubocop-gradual
  • rubocop-md
  • rubocop-rake
  • rubocop-shopify
  • rubocop-thread_safety
  • standard
  • standard-performance (incl. rubocop-performance)
  • standard-custom
  • standard-rubocop-lts (ruby version-specific rules)

And optionally, if you are using RSpec:

  • rubocop-rspec

And optionally, if you are building a RubyGem:

  • rubocop-packaging

And optionally, if you are building a Rails app:

  • standard-rails (incl. rubocop-rails)
  • betterlint

Awareness of rubocop's lack of SemVer adherence isn't evenly dispersed in the Ruby community.

The RuboCop team has reasons for not following SemVer.

NOTE: They think they are following SemVer, but their interpretation differs from mine, and seems to differ from the intent of SemVer's creator.

Explanation of non-SemVer compliance, @bbatsov

The purpose of this gem is to constrain the rubocop dependency of a project in a SemVer compliant (Semantic Versioning, Major Versions are Not Sacred) way that aligns with its desired minimum compatible/supported Ruby version. Secondary purpose is to provide default configurations for a bevy of RuboCop-related plugins.

πŸ’Ž Ruby Version Support

This gem facilitates equivalent of adding a ~> version constrained rubocop(-ish +more) dependency, thus minimizing the risk of a rubocop minor / patch upgrade breaking the build.

What's that you say?

This gem will install a suite of tools that will analyze & lint code intended to support any version of Ruby >= 2.0.

This gem helps insulate projects from RuboCop churn by enshrining many conventions that have been shown over years to reduce problems.

Background

Each spring rubocop drops the ability to install and run rubocop on an EOL'd Ruby. Eventually rubocop will drop the ability to analyze code intended to support an EOL'd Ruby, as they already have for Ruby 1.9. RuboCop has never run properly on Ruby 1.8. This gem, via standard (Standard Ruby), allows RuboCop to analyze Ruby 3.1 code, by turning off certain rules that only apply to later Rubies.

When the rubocop team makes any of these changes they only bump the minor version of RuboCop, in violation of SemVer (they disagree).

In other words, RuboCop intentionally does not bump the major version when they drop analysis, runtime, or installation support for a given version of Ruby.

This is a primary raison d’Γͺtre for this project. To get a better understanding of how SemVer is intended to work read this article from the creator of SemVer:

πŸ‘ͺ A Gem Family

The rubocop-lts family of gems has a version supporting any version of Ruby you need. They can be used as development dependencies for libraries or applications.

πŸ—Ώ Stable

All releases of this gem are stable releases. We do not release new versions for every release of rubocop, as this gem is tied to standard (Standard Ruby). A typical release cycle for a gem in the rubocop-lts family is roughly every six months, though eventually analysis support for an old version of Ruby will be dropped. When that happens releases of the rubocop-lts gem for that version of Ruby will (mostly) cease.

✨ Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add rubocop-ruby3_1 -r false

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install rubocop-ruby3_1

πŸ”§ Basic Usage

If you are using Rails, building a Rubygem, or not using RSpec, see "Advanced Usage". Otherwise, if you using this in plain Ruby and RSpec, you can add to the top of your project's .rubocop.yml configuration file:

inherit_gem:
  rubocop-ruby3_1: rubocop.yml

Among many other settings, this has the effect of declaring the following:

AllCops:
  NewCops: enable

Let's talk about these settings. (TODO: Document some of the other settings!)

βš™οΈ NewCops: enable

Upgrades to the latest RuboCop can include all kinds of changes, including removing support for the version of Ruby your project uses, or adding a cop that may not work with some of your syntax (e.g. some use cases of 'module_function`). Accepting new cops arriving in a new version of RuboCop can feel risky, especially when it doesn't follow SemVer.

But this gem shoehorns RuboCop into SemVer, under the watchful eye of standard (Standard Ruby)... so NewCops is now safe(r)! If you use a dependency greening tool like GitHub's dependabot, or the excellent alternatives depfu, and renovate, then you can see the effect of a minor / major version bump in your CI Build!

Advanced Usage

Linting Ruby + RSpec

inherit_gem:
  rubocop-ruby3_1: rubocop-lts/ruby_rspec.yml
  # Note: technically the above is the same as the "Basic Usage" below, so if specificity is not your jam:
#  rubocop-ruby3_1: rubocop.yml

Linting Ruby w/o RSpec

inherit_gem:
  rubocop-ruby3_1: rubocop-lts/ruby.yml

Linting Rails + RSpec

inherit_gem:
  rubocop-ruby3_1: rubocop-lts/rails_rspec.yml

Linting Rails w/o RSpec

inherit_gem:
  rubocop-ruby3_1: rubocop-lts/rails.yml

Linting a RubyGem + RSpec

inherit_gem:
  rubocop-ruby3_1: rubocop-lts/rubygem_rspec.yml

Linting a RubyGem w/o RSpec

inherit_gem:
  rubocop-ruby3_1: rubocop-lts/rubygem.yml

πŸ’» Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests w/ coverage, or bin/rake to run tests w/ coverage, and linting. 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.

πŸš€ Release Instructions

See CONTRIBUTING.md.

⚑️ Contributing

See CONTRIBUTING.md

🌈 Contributors

Contributors

Made with contributors-img.

πŸ“„ License

The gem is available as open source under the terms of the MIT License License: MIT. See LICENSE.txt for the official Copyright Notice.

Project Logos (rubocop-ruby3_1)

See docs/images/logo/README.txt

Organization Logo (rubocop-lts)

Author: Yusuf Evli Source: Unsplash License: Unsplash License

Β© Copyright

🀝 Code of Conduct

Everyone interacting in this 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-ruby3_1", "~> 2.0")