When there is a comment between 2 gems in the Gemfile, the OrderedGems cop should still enforce that gems are listed alphabetically.
The docs make it clear that if there's an empty line between them, they don't need to be sorted. But if a comment is between them, that seems different and I would expect it to sort them.
My reasoning is as followed:
An empty line indicates that they are separate groups of gems.
A comment, on the other hand, does not indicate a separate group--it may indicate that one of the gems within this group requires some explanations. If you've enabled Style/InlineComment, then you have no other choice but to place the comment on the line above them gem, even if it's in middle of a group.
Rubocop should detect 1 offense, just as it does when the comment is not there
Rubocop does not detect the offense.
$ cat Gemfile
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'rubocop'
# A comment
gem 'parser'
$ rubocop --only Bundler/OrderedGems
Inspecting 1 file
.
1 file inspected, no offenses detected
$ rubocop -V
0.47.1 (using Parser 2.3.3.1, running on ruby 2.2.2 x86_64-linux)
I agree. I use comments in the Gemfile like that to explain why we have to use a branch of a gem, for instance.
Yeah, that's definitely a bug. Thanks for spotting and reporting it.
@pocke some of us think this behavior is a bug, but it looks like you intended it to behave this way. Would you kindly contribute your opinion here?
but it looks like you intended it to behave this way.
I reconsidered this implementation. I think the proposed behavior is correct. However, current behavior is correct, too.
I have investigated several Gemfiles. Then, I can find that both usages.
for example
### proposed usage
# Comment is for one gem description.
# This example is created by `rails new` command.
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
### A usage that is current behavior
# Command is a description for a gem group.
# Authentication
gem 'devise'
gem 'omniauth'
gem 'omniauth-github'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
# Web API
gem 'octokit', '~> 4.1.0'
gem 'koala', '~> 2.2'
gem 'twitter'
So, I think we should implement the proposed behavior as an option(EnforcedStyle).
And the proposed behavior should be used as default.
WDYT?
If nobody is working on this, I'll try to implement it.
@konto-andrzeja Thanks!!! I don't have time for this issue, so that is very helpful.
Most helpful comment
I reconsidered this implementation. I think the proposed behavior is correct. However, current behavior is correct, too.
I have investigated several Gemfiles. Then, I can find that both usages.
for example
So, I think we should implement the proposed behavior as an option(
EnforcedStyle).And the proposed behavior should be used as default.
WDYT?