Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

[Feature] bundle canonical#6623

Closed
agrim123 wants to merge 12 commits intorubygems:masterfrom
agrim123:bundle-canonical
Closed

[Feature] bundle canonical#6623
agrim123 wants to merge 12 commits intorubygems:masterfrom
agrim123:bundle-canonical

Conversation

@agrim123
Copy link
Copy Markdown
Contributor

@agrim123 agrim123 commented Jul 11, 2018

Basic Idea

  • To prettify the gemfile (includes the summary of gems)
  • Give it consistent ordering and formatting

Usage

bundle canonical

bundle canonical --view

By default changes the gemfile and on using --view option displays what the gemfile would look like without altering it.

Specs are failing. Working on them

@agrim123 agrim123 changed the title [Feature Request] bundle canonical [Feature] bundle canonical Jul 11, 2018
Copy link
Copy Markdown
Contributor

@segiddins segiddins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need an RFC before we can merge, but I think this is a cool start!

Prettifies the Gemfile by giving it consistent ordering and formatting.
D
method_option "view", :type => :boolean
def canonical
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we''l need to come up with a better name for this, but we can do so in the RFC

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking maybe prettify or something on those lines.

# frozen_string_literal: true

module Bundler
class Gemfile
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class definitely should be named something different GemfileRewriter or something

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think GemfileRewriterwould suit because we are not changing gemfile anywhere. We are extracting things out of it. Need to think of something else 🤔

gem "rspec"
end
E
expect(subject.groups_wise(a[2][1], a[2][0]).join("\n").gsub(/\n{3,}/, "\n\n")).to eq(strip_whitespace(expected))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are very hard to read -- maybe extract into some variable names?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Fixing them.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

I'm unsure about this change, rubocop already provides a bunch of style rules for Gemfiles, and people caring about style & prettyness are probably using rubocop already. For those people, this new command will probably not be useful since it's very likely that it won't be able to achieve the level of flexibility rubocop already has. So in my opinion any efforts towards standarizing Gemfile's appearance should be focused on improving existing and adding new cops for rubocop.

@agrim123
Copy link
Copy Markdown
Contributor Author

agrim123 commented Jul 24, 2018

@deivid-rodriguez I agree but we are basically making the Gemfile uniform and if required with the summary of the gems. I don't think rubocop provides this.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

deivid-rodriguez commented Jul 24, 2018

This is what rubocop currently provides: http://docs.rubocop.org/en/latest/cops_bundler/. Plus this one cop in the works. Does it not overlap?

@agrim123
Copy link
Copy Markdown
Contributor Author

agrim123 commented Jul 27, 2018

This seems to hijack this PR 😅.
@segiddins What do you suggest? Should we add something more to this command?
I think this to be handy because it is inbuilt in bundler and easy to use, maybe.

@segiddins
Copy link
Copy Markdown
Contributor

I am still in favor of bundler having this functionality built in -- it behaves fundamentally differently from rubocop, since it operates on the semantic content of the gemfile, rather than just the ruby source

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

@segiddins Can you explain the difference a bit more? From the PR description, "To prettify the gemfile", "Give it consistent ordering and formatting", to me it looks very similar to what rubocop tries to achieve.

@segiddins
Copy link
Copy Markdown
Contributor

RuboCop doesn’t actually eval the gemfile, so it won’t know the underlying contents, such as if Ruby code is used in conditionals

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Mmm, I think I get what you mean. bundler could do dynamic analysis on the Gemfile whereas rubocop only does static analysis. So if for example someone does:

database_gem = "pg"
gem database_gem
gem "decidim"

bundler will be able to "properly" sort the gems but rubocop will not?

I'm still hesitant about whether this is worth maintaining... Any more opinions?

@segiddins
Copy link
Copy Markdown
Contributor

@deivid-rodriguez comments on the RFC appreciated :)
rubygems/rfcs#15

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Ooops, sorry for commenting in the wrong place. I'll move my hesitations there 😄

@fatkodima
Copy link
Copy Markdown
Contributor

Personally, I don't see much benefits (if at all) of adding and using this. Style checking and formatting should be done by external linters, such as rubocop. And for short summaries for gems - it's pointless to add summaries for all gems in Gemfile, as this is intended for. Usually people annotate only a couple of gems in Gemfile and it is not that hard to do it manually.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Closing this as per rubygems/rfcs#15 (comment).

Thanks for the work and discussion in any case 🙏.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants