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

Cop idea: Read ruby version from .ruby-version source in Gemfile #11744

Closed
anthony-robin opened this issue Mar 29, 2023 · 4 comments
Closed

Cop idea: Read ruby version from .ruby-version source in Gemfile #11744

anthony-robin opened this issue Mar 29, 2023 · 4 comments

Comments

@anthony-robin
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently, the Ruby version for a project is duplicated twice which is not very practical when a Ruby update is necessary as it has to be modified in both places:

  • once in the Gemfile

    # Gemfile
    
    source "https://rubygems.org"
    git_source(:github) { |repo| "https://github.com/#{repo}.git" }
    
    ruby "3.1.1"
    
    # ...
  • once in .ruby-version

    3.1.1
    

Describe the solution you'd like

It could be great to have a cop that detects it and replace the Gemfile line reading it from .ruby-version (the cop should automatically autocorrect it as well)

# Gemfile

ruby File.read('.ruby-version').strip

Describe alternatives you've considered

/

Additional context

What do you think about this cop ? Do you see any reason to not make a cop that detect this behavior ?
(sorry if there was already discussions about this, I didn't find any of them in the repo, feel free to close if this subject is not relevant)

Thank you :)

@andyw8
Copy link
Contributor

andyw8 commented Mar 30, 2023

This would be better suited for rubocop than rubocop-rails.

@anthony-robin
Copy link
Contributor Author

Right, can someone transfer it to the main repository ?

@koic koic transferred this issue from rubocop/rubocop-rails Mar 30, 2023
@koic
Copy link
Member

koic commented Mar 30, 2023

I'm not sure if this makes sense, for the following reasons:

  • Case where tools with formats different from .ruby-version such as asdf are used
  • Case where Docker images are used and .ruby-version is not used
  • Case where specification on Heroku is required Ruby version in Gemfile, but development is not dependent on .ruby-version

I think it's not a suitable enforcement rule for the above cases. In other words, I'm wondering if it should not be supported in the RuboCop core as a general purpose rule, as this feature request seems to be specific to an application development environment.

@anthony-robin
Copy link
Contributor Author

Thank you for the explanation @koic !

Indeed, there are too many edge cases to make it an enforcement rule 👍

@koic koic closed this as not planned Won't fix, can't repro, duplicate, stale Dec 30, 2023
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

No branches or pull requests

3 participants