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

Insert gems alphabetically #915

Open
toobulkeh opened this issue May 17, 2018 · 3 comments
Open

Insert gems alphabetically #915

toobulkeh opened this issue May 17, 2018 · 3 comments
Labels
Enhancement Features we're considering adding

Comments

@toobulkeh
Copy link
Contributor

Here is the Gemfile that is created when suspenders generates an app now:

source "https://rubygems.org"

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

ruby "2.5.0"

gem "autoprefixer-rails"
gem "flutie"
gem "honeybadger"
gem "jquery-rails"
gem "pg", "~> 0.18"
gem "puma"
gem "rack-canonical-host"
gem "rails", "~> 5.1.4"
gem "recipient_interceptor"
gem "sass-rails", "~> 5.0"
gem "skylight"
gem "sprockets", ">= 3.0.0"
gem "suspenders"
gem "title"
gem "uglifier"


group :development do
  gem "listen"
  gem "rack-mini-profiler", require: false
  gem "spring"
  gem "web-console"
end

group :development, :test do
  gem "awesome_print"
  gem "bundler-audit", ">= 0.5.0", require: false
  gem "dotenv-rails"
  gem "pry-byebug"
  gem "pry-rails"
end

group :test do
  gem "formulaic"
  gem "launchy"
  gem "simplecov", require: false
  gem "timecop"
  gem "webmock"
end

group :production do
  gem "rack-timeout"
end

gem 'high_voltage'
gem 'bourbon', '~> 5.0'
gem 'neat', '~> 2.1'
gem 'refills', group: [:development, :test]
gem 'spring-commands-rspec', group: :development
gem 'rspec-rails', '~> 3.6', group: [:development, :test]
gem 'shoulda-matchers', group: :test
gem 'capybara-webkit', group: :test
gem 'simple_form'
gem 'bullet', group: [:development, :test]
gem 'factory_bot_rails', group: [:development, :test]

Not sure what happened -- but it use to be cleaner, like:

source "https://rubygems.org"

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

ruby "2.5.0"

gem "autoprefixer-rails"
gem "bourbon", "~> 5.0"
gem "bullet"
gem "factory_bot_rails"
gem "flutie"
gem "high_voltage"
gem "honeybadger"
gem "jquery-rails"
gem "neat", "~> 2.1"
gem "pg", "~> 0.18"
gem "puma"
gem "rack-canonical-host"
gem "rails", "~> 5.1.4"
gem "recipient_interceptor"
gem "sass-rails", "~> 5.0"
gem "simple_form"
gem "skylight"
gem "sprockets", ">= 3.0.0"
gem "suspenders"
gem "title"
gem "uglifier"

group :development do
  gem "listen"
  gem "rack-mini-profiler", require: false
  gem "spring"
  gem "spring-commands-rspec"
  gem "web-console"
end

group :development, :test do
  gem "awesome_print"
  gem "bundler-audit", ">= 0.5.0", require: false
  gem "dotenv-rails"
  gem "pry-byebug"
  gem "pry-rails"
  gem "rspec-rails", "~> 3.6"
  gem "refills"
end

group :test do
  gem "capybara-webkit"
  gem "formulaic"
  gem "launchy"
  gem "shoulda-matchers"
  gem "simplecov", require: false
  gem "timecop"
  gem "webmock"
end

group :production do
  gem "rack-timeout"
end

Differences:

  1. Alphabetize
  2. Using groups
  3. Double-quotes
@mike-burns
Copy link
Contributor

It's true, this came from a switch to using Rails gem helper.

I was not thrilled with the result but assumed no one else cared. But apparently people do!

I think the thing to do is to write a custom gem helper that gets us back to where we were: it would insert the gem alphabetically, in the appropriate group, using double quotes.

I don't have the bandwidth to do that over the new few months, unfortunately, but it seems like a surprisingly fun method to write.

mike-burns added a commit that referenced this issue Mar 13, 2021
For too long we have [suffered] under the tyranny of Rails' mediocre `gem`
action! But Rails 6 took it a step too far: it [no longer] supports a
`destroy` generator.

[suffered]: #915
[no longer]:#1061 (comment)

So it's high time we make our own. In the process, encode the rules we
like to see: keep gems alphabetical, and use the `group` block syntax
instead of the `:group` argument.

When inserting a gem, we have to consider two cases: do we have a group
specification? If we don't have a group name, insert it alphabetically
before the first non-indented `gem "..."` declaration. If we do have a
group name, find the block for that group and insert it alphabetically.
But there's also the chance thar we are the first to add this group, in
which case we should add the group with the `gem` line at the end.

When removing a group, we again consider the groups case. If there is no
group specification, remove the first matching non-indented `gem "..."`
declaration. If we have a group spec, find the group block in the
Gemfile and remove it. If there is no such group block, do nothing.

Closes #915.
@thiagoa thiagoa changed the title Gemfile a-mess Insert gems alphabetically Oct 1, 2021
@stevepolitodesign
Copy link
Contributor

stevepolitodesign commented May 10, 2024

Now that #1135 has been merged, the suspenders:cleanup:gemfile task introduced in #1181 is available, and runs when suspending new applications. However, it does not alphabetize the gems.

Do we still feel it's important to alphabetize the gems? Or, is the task introduced in #1181 sufficient enough?

@mike-burns
Copy link
Contributor

I think Standard does that for us.

@stevepolitodesign stevepolitodesign added the Enhancement Features we're considering adding label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Features we're considering adding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants