Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #6945] Drop support for Ruby 2.2 #7026

Merged
merged 4 commits into from
May 8, 2019

Conversation

koic
Copy link
Member

@koic koic commented May 8, 2019

Fixes #6945.

This is a big change. The major changes are split into commits and left in the message. Notable changes to users are:

Drop support for Ruby 2.2

By convention, a year after Ruby became an EOL, it seems that the old Ruby version support has been dropped. I'm not sure if it's good to drop Ruby 2.3 support, but it's good time to drop Ruby 2.2 support.

Set default EnforcedStyle to squiggly option for Layout/IndentHeredoc and auto_detection option is removed

Because we no longer use Ruby 2.2, the original default auto_detection option is never used. Makes squiggly option enabled in Ruby 2.3 or higher a new default.

Set default EnforcedStyle to always option for Style/FrozenStringLiteralComment and when_needed option is removed

Because we no longer use Ruby 2.2, the original default when_needed option is never used. Makes always option enabled in Ruby 2.3 or higher a new default.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@bbatsov
Copy link
Collaborator

bbatsov commented May 8, 2019

Seems something's wrong with JRuby.

@koic koic force-pushed the drop_support_for_ruby_2_2 branch 2 times, most recently from ac04961 to 3c57846 Compare May 8, 2019 09:48
koic added 4 commits May 8, 2019 19:11
Fixes rubocop#6945.

By convention, a year after Ruby became an EOL, it seems that the old
Ruby version support has been dropped. I'm not sure if it's good to drop
Ruby 2.3 support, but it's good time to drop Ruby 2.2 support.
This commit sets default `EnforcedStyle` to `squiggly` option for
`Layout/IndentHeredoc` and `auto_detection` option is removed.

Because we no longer use Ruby 2.2, the original default `auto_detection`
option is never used. Makes `squiggly` option enabled in Ruby 2.3 or
higher a new default.
…lComment`

This commit sets default `EnforcedStyle` to `always` option for
`Style/FrozenStringLiteralComment` and `when_needed` option is removed.

Because we no longer use Ruby 2.2, the original default `when_needed`
option is never used. Makes `always` option enabled in Ruby 2.3 or
higher a new default.
@koic koic force-pushed the drop_support_for_ruby_2_2 branch from 3c57846 to 05f25f3 Compare May 8, 2019 10:15
@koic
Copy link
Member Author

koic commented May 8, 2019

JRuby has a squiggly heredoc feature incompatibility with MRI. I updated it to pass the tests.

@bbatsov bbatsov merged commit 5ffddbb into rubocop:master May 8, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented May 8, 2019

Fantastic work! 🙇

JRuby has a squiggly heredoc feature incompatibility with MRI. I updated it to pass the tests.

Incompatible in which way?

@koic koic deleted the drop_support_for_ruby_2_2 branch May 8, 2019 22:00
@koic
Copy link
Member Author

koic commented May 8, 2019

Incompatibility have arisen in squiggly heredoc that use single quotes.

# example.rb
source = <<~'RUBY'
  def say
    puts 'hello'
  end
RUBY

puts source

ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin17]

% ruby example.rb
def say
  puts 'hello'
end

jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3

% ruby example.rb
def say
puts 'hello'
end

It may be related to the following issue.
jruby/jruby#4260

As a result, RuboCop has not replaced the following test code with squiggly heredoc.

expect_offense(<<-'RUBY'.strip_indent)

@koic koic mentioned this pull request May 9, 2019
8 tasks
koic added a commit to koic/rubocop that referenced this pull request May 9, 2019
Follow up rubocop#7026.

This PR updates the following deficiencies.

- The default `EnforcedStyle` of `Style/FrozenStringLiteralComment is `always`,
 so duplicate settings are removed from .rubocop.yml.
- Remove unnecessary logic because `SupportedStyles: auto_detection` has been
removed from `Layout/IndentHeredoc`.
- Remove the check for warn introduced in rubocop#6227.
- Remove specification of `let(:ruby_version) { 2.3 }` written in spec.
- Remove unnecessary code using Ruby version
- Updated the README to make JRuby support 9.1 or higher because JRuby
 9.0 compatible with Ruby 2.2.

```console
% ruby -v
jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server
VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
% ruby -v
jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server
VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
% ruby -v
jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server
VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
```
bbatsov pushed a commit that referenced this pull request May 9, 2019
Follow up #7026.

This PR updates the following deficiencies.

- The default `EnforcedStyle` of `Style/FrozenStringLiteralComment is `always`,
 so duplicate settings are removed from .rubocop.yml.
- Remove unnecessary logic because `SupportedStyles: auto_detection` has been
removed from `Layout/IndentHeredoc`.
- Remove the check for warn introduced in #6227.
- Remove specification of `let(:ruby_version) { 2.3 }` written in spec.
- Remove unnecessary code using Ruby version
- Updated the README to make JRuby support 9.1 or higher because JRuby
 9.0 compatible with Ruby 2.2.

```console
% ruby -v
jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server
VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
% ruby -v
jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server
VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
% ruby -v
jruby 9.2.7.0 (2.5.3) 2019-04-09 8a269e3 Java HotSpot(TM) 64-Bit Server
VM 25.5-b02 on 1.8.0_05-b13 +jit [darwin-x86_64]
```
tatsuyafw added a commit to tatsuyafw/hashdiff that referenced this pull request Jun 13, 2019
Rubocop drops Ruby 2.2 support.

rubocop/rubocop#7026

To fix the failed CI, drops Ruby 2.2 and below.
tatsuyafw added a commit to tatsuyafw/hashdiff that referenced this pull request Jun 13, 2019
Rubocop drops Ruby 2.2 support.

rubocop/rubocop#7026

To fix the failed CI, drops Ruby 2.2 and below.
koic added a commit to koic/rubocop that referenced this pull request Jun 23, 2019
Follow up https://github.com/rubocop-hq/rubocop/pull/7026/files#diff-e874291b0f90e09a05cf52715a768e87.

It is no longer necessary to judge `rails (Active Support)` style or not
when Ruby version supported by RuboCop is Ruby 2.3 or higher.

The following is the changes in PR rubocop#7026.

```diff
- if target_ruby_version >= 2.3
-   :squiggly
- elsif rails?
-   :active_support
- end
+ :squiggly
```

With this change, cops using `SafeMode` module have been removed from
RuboCop core.

And I investigated RuboCop Performance, RuboCop Rails and RuboCop RSpec
about using `SafeMode` module. As a result, only RuboCop Performance
uses `SafeMode` module now. I'd like to think separately about what to
do with `SafeMode` module. It is not yet known if `SafeMode` module
has been moved to RuboCop Performance and there are no problems.
bbatsov pushed a commit that referenced this pull request Jun 23, 2019
Follow up https://github.com/rubocop-hq/rubocop/pull/7026/files#diff-e874291b0f90e09a05cf52715a768e87.

It is no longer necessary to judge `rails (Active Support)` style or not
when Ruby version supported by RuboCop is Ruby 2.3 or higher.

The following is the changes in PR #7026.

```diff
- if target_ruby_version >= 2.3
-   :squiggly
- elsif rails?
-   :active_support
- end
+ :squiggly
```

With this change, cops using `SafeMode` module have been removed from
RuboCop core.

And I investigated RuboCop Performance, RuboCop Rails and RuboCop RSpec
about using `SafeMode` module. As a result, only RuboCop Performance
uses `SafeMode` module now. I'd like to think separately about what to
do with `SafeMode` module. It is not yet known if `SafeMode` module
has been moved to RuboCop Performance and there are no problems.
koic added a commit to koic/rubocop that referenced this pull request Jun 25, 2019
Follow up rubocop#7026.

This PR uses squiggly heredoc for node patterns and eval.

The following offenses were found as a result of this change.

```console
% bundle exec rake

(snip)

Offenses:

lib/rubocop/cop/lint/safe_navigation_chain.rb:33:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
        { ...
^^^^^^^^^
lib/rubocop/cop/mixin/enforce_superclass.rb:9:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
        (class (const _ !:#{base::SUPERCLASS}) #{base::BASE_PATTERN}...) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/mixin/enforce_superclass.rb:13:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
        [!^(casgn nil? :#{base::SUPERCLASS} ...) (send (const nil?:Class)
:new #{base::BASE_PATTERN})] ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/style/struct_inheritance.rb:33:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
           {(send (const nil? :Struct) :new ...) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/style/format_string.rb:44:1: C: Layout/IndentHeredoc:
Use 2 spaces for indentation in a heredoc.
        { ...
^^^^^^^^^

1083 files inspected, 5 offenses detected
RuboCop failed!
```

And the following is the difference of the cop code generated by
`bundle exec rake new_cop[Department/CopName]`.

```diff
  class Foo < Cop
    # TODO: Implement the cop in here.
    #
    # In many cases, you can use a node matcher for matching node pattern.
    # See https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/node_pattern.rb
    #
    # For example
    MSG = 'Use `#good_method` instead of `#bad_method`.'.freeze

-   def_node_matcher :bad_method?, <<-PATTERN
+   def_node_matcher :bad_method?, <<~PATTERN

      (send nil? :bad_method ...)
    PATTERN

    def on_send(node)
      return unless bad_method?(node)

      add_offense(node)
    end
  end
```
bbatsov pushed a commit that referenced this pull request Jun 26, 2019
Follow up #7026.

This PR uses squiggly heredoc for node patterns and eval.

The following offenses were found as a result of this change.

```console
% bundle exec rake

(snip)

Offenses:

lib/rubocop/cop/lint/safe_navigation_chain.rb:33:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
        { ...
^^^^^^^^^
lib/rubocop/cop/mixin/enforce_superclass.rb:9:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
        (class (const _ !:#{base::SUPERCLASS}) #{base::BASE_PATTERN}...) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/mixin/enforce_superclass.rb:13:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
        [!^(casgn nil? :#{base::SUPERCLASS} ...) (send (const nil?:Class)
:new #{base::BASE_PATTERN})] ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/style/struct_inheritance.rb:33:1: C:
Layout/IndentHeredoc: Use 2 spaces for indentation in a heredoc.
           {(send (const nil? :Struct) :new ...) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/rubocop/cop/style/format_string.rb:44:1: C: Layout/IndentHeredoc:
Use 2 spaces for indentation in a heredoc.
        { ...
^^^^^^^^^

1083 files inspected, 5 offenses detected
RuboCop failed!
```

And the following is the difference of the cop code generated by
`bundle exec rake new_cop[Department/CopName]`.

```diff
  class Foo < Cop
    # TODO: Implement the cop in here.
    #
    # In many cases, you can use a node matcher for matching node pattern.
    # See https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/node_pattern.rb
    #
    # For example
    MSG = 'Use `#good_method` instead of `#bad_method`.'.freeze

-   def_node_matcher :bad_method?, <<-PATTERN
+   def_node_matcher :bad_method?, <<~PATTERN

      (send nil? :bad_method ...)
    PATTERN

    def on_send(node)
      return unless bad_method?(node)

      add_offense(node)
    end
  end
```
koic added a commit to koic/rubocop that referenced this pull request Aug 21, 2019
jruby/jruby#4260 has been resolved and
JRuby 9.2.8.0  is available on CircleCI.
https://hub.docker.com/r/circleci/jruby/tags

```console
% docker run --rm -it circleci/jruby:9.2
Unable to find image 'circleci/jruby:9.2' locally
9.2: Pulling from circleci/jruby
9cc2ad81d40d: Pull complete
e6cb98e32a52: Pull complete
ae1b8d879bad: Pull complete
2383fa4462e7: Pull complete
7ac3ce9f2067: Pull complete
ce9a16d8ddcb: Pull complete
b250e79d9c7f: Pull complete
ce3b7f0ecca6: Pull complete
2405779516de: Pull complete
902dc7b355a1: Pull complete
432a6994cb77: Pull complete
66a081bddadb: Pull complete
1576af617cb5: Pull complete
4233b310ce28: Pull complete
51c0ac4a73c0: Pull complete
c43fdb6f1fe8: Pull complete
909d5a0f7f69: Pull complete
940e076596c5: Pull complete
c6abd11f682b: Pull complete
678a31b2fb39: Pull complete
Digest:
sha256:ee43918172710e4871054ce450da6e5f6d66cdeb1fe8397d356742bf142f20a2
Status: Downloaded newer image for circleci/jruby:9.2
$ ruby -v
jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM
25.222-b10 on 1.8.0_222-b10 +jit [linux-x86_64]
```

This PR aims to solve the following issues solved by JRuby.

- rubocop#7026 (comment)
- rubocop#7173 (comment)
- rubocop#7229 (comment)
- rubocop#7228 (comment)

It also removes unnecessary `strip_indent`.
bbatsov pushed a commit that referenced this pull request Aug 21, 2019
jruby/jruby#4260 has been resolved and
JRuby 9.2.8.0  is available on CircleCI.
https://hub.docker.com/r/circleci/jruby/tags

```console
% docker run --rm -it circleci/jruby:9.2
Unable to find image 'circleci/jruby:9.2' locally
9.2: Pulling from circleci/jruby
9cc2ad81d40d: Pull complete
e6cb98e32a52: Pull complete
ae1b8d879bad: Pull complete
2383fa4462e7: Pull complete
7ac3ce9f2067: Pull complete
ce9a16d8ddcb: Pull complete
b250e79d9c7f: Pull complete
ce3b7f0ecca6: Pull complete
2405779516de: Pull complete
902dc7b355a1: Pull complete
432a6994cb77: Pull complete
66a081bddadb: Pull complete
1576af617cb5: Pull complete
4233b310ce28: Pull complete
51c0ac4a73c0: Pull complete
c43fdb6f1fe8: Pull complete
909d5a0f7f69: Pull complete
940e076596c5: Pull complete
c6abd11f682b: Pull complete
678a31b2fb39: Pull complete
Digest:
sha256:ee43918172710e4871054ce450da6e5f6d66cdeb1fe8397d356742bf142f20a2
Status: Downloaded newer image for circleci/jruby:9.2
$ ruby -v
jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM
25.222-b10 on 1.8.0_222-b10 +jit [linux-x86_64]
```

This PR aims to solve the following issues solved by JRuby.

- #7026 (comment)
- #7173 (comment)
- #7229 (comment)
- #7228 (comment)

It also removes unnecessary `strip_indent`.
@bquorning bquorning mentioned this pull request Sep 1, 2019
8 tasks
koic added a commit to koic/rubocop that referenced this pull request May 18, 2022
Follow up rubocop#10632 (comment).

Reverts part of rubocop#6766, rubocop#7026, and rubocop#7030.

Only the Ruby version (2.2) to runtime should have been dropped, not code analysis.
This PR makes Ruby 2.2 code analysis with `TargetRubyVersion: 2.2`.
It aims to solve essentially the same problem as rubocop#10626, rubocop#10632, and rubocop#10640.

Previously, there was the following default enforced style `when_needed` for
`Style/FrozenStringLiteralComment` cop.

```ruby
# @example EnforcedStyle: when_needed (default)
#   # The `when_needed` style will add the frozen string literal
#   # to files only when the `TargetRubyVersion` is set to 2.3+.
#   # bad
#   module Foo
#     # ...
#   end
#
#   # good
#   # frozen_string_literal: true
#
#   module Foo
#     # ...
#   end
```

This PR does not restore that option, but sets the `minimum_target_ruby_version 2.3`
to make `always (default)` apply by default. It is a simple solution that does not
handle frozen literal magic comment added in Ruby 2.3 when `TargetRubyVersion` is
Ruby 2.2 or lower.
koic added a commit to koic/rubocop-rails that referenced this pull request Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drop support for Ruby 2.2 and 2.3
2 participants