Skip to content

Fix detection of ruby versions through the gemfile below 2.7 #13112

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

Merged
merged 1 commit into from
Aug 11, 2024

Conversation

Earlopain
Copy link
Contributor

Some things going on here:

If I have a gemspec saying target_ruby_version ">= 2.6", what RuboCop will actually use is 2.7 because it is the default version. All versions prior are simply discarded, even if rubocop is able to provide accurate results for these older versions.

There were tests for this but I believe that they lost what they actually were testing against during some refactor, somewhere here: #9515, #10629, and the PRs removing and reading analysis for older rubies.

This test for example used to check that the returned ruby version is 2.4 and not 2.3 which it didn't know how to analyse at one point (i.e. don't select versions below what we are currently supporting):

          it 'sets target_ruby from required_ruby_version from inclusive requirement range' do
            content = <<~HEREDOC
              Gem::Specification.new do |s|
                s.name = 'test'
                s.required_ruby_version = Gem::Requirement.new('>= 2.3.1')
                s.licenses = ['MIT']
              end
            HEREDOC

            create_file(gemspec_file_path, content)
            expect(target_ruby.version).to eq default_version
          end

Now it checks that 2.7 is the returned version, which doesn't make much sense since older versions are able to be analysed.

For the < 3.0.0 case, I think its ok to select the earliest version supported (currently 2.0). Selecting 2.7 (or whatever the default may be in the future) surely isn't the intention.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

Some things going on here:

If I have a gemspec saying target_ruby_version ">= 2.6", what RuboCop actually will use is 2.7
because it is the default version. All versions prior are simply discarded, even if rubocop is
able to provide accurate results for these older versions.

There were tests for this but I believe that they lost what they actually were testing against during
some refactor, somewhere here: rubocop#9515, rubocop#10629, and the PRs removing and reading analysis for older rubies.

This test for example used to check that the returned ruby version is 2.4 and not 2.3 which it didn't know
how to analyse at one point:

```rb

          it 'sets target_ruby from required_ruby_version from inclusive requirement range' do
            content = <<~HEREDOC
              Gem::Specification.new do |s|
                s.name = 'test'
                s.required_ruby_version = Gem::Requirement.new('>= 2.3.1')
                s.licenses = ['MIT']
              end
            HEREDOC

            create_file(gemspec_file_path, content)
            expect(target_ruby.version).to eq default_version
          end
```

Now it checks that 2.7 is the returned version, which doesn't make much sense.

For the `< 3.0.0` case, I think its ok to select the earliest version supported (currently 2.0).
Selecting 2.7 (or whatever the default may be in the future) surely isn't the intention.
@Earlopain Earlopain force-pushed the gemspec-ruby-detection branch from c61a465 to cf59e52 Compare August 11, 2024 14:10
@koic koic merged commit 35bf30f into rubocop:master Aug 11, 2024
22 checks passed
@koic
Copy link
Member

koic commented Aug 11, 2024

Thanks!

@Earlopain Earlopain deleted the gemspec-ruby-detection branch August 19, 2024 17:19
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy