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
Replace regex with Bundler::LockfileParser
#12180
Conversation
6a4dbc9
to
2d52783
Compare
Is the |
2d52783
to
6047cb7
Compare
a9f4871
to
665c0bf
Compare
lib/rubocop/config.rb
Outdated
def inspect # :nodoc: | ||
"#<#{self.class.name}:#{object_id} @loaded_path=#{loaded_path}>" | ||
end | ||
|
||
private | ||
|
||
def target_rails_version_from_bundler_lock_file | ||
@target_rails_version_from_bundler_lock_file ||= read_rails_version_from_bundler_lock_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this memoization because:
- If
read_rails_version_from_bundler_lock_file
returnednil
, it wouldn't memoize correctly and would be trying to parse the lockfile on every call anyway - This value is only accessed from
#target_rails_version
, which is itself memoized
Hey @koic! I don't see any firm evidence that it's intended to be public (e.g. YARD docs), but I think it's very likely to be the case.
Package management is central to an ecosystem, and being able to introspect dependencies is pretty core to a bunch of tooling. If it's not public, we should perhaps try to make it public, like how Being dependant on |
@deivid-rodriguez @hsbt May I ask the Bundler development team, Is |
145c615
to
4557ea0
Compare
Hei @koic. |
@deivid-rodriguez I've come to understand the |
No problem! |
I don't mind using |
4557ea0
to
edd48fc
Compare
@bbatsov добър вечер! I've just rebased it. This PR builds on top of #12186, which needs to be reviewed and shipped first. After that, I think this PR is also ready for review/merge (just look at the last commit) |
edd48fc
to
3e61208
Compare
The commits related to the changes in #12180 are mixed in. Can you leave the change for only "Replace regex with |
It just occurred to me that RuboCop doesn't have a runtime dependency on Bundler. This means to utilize Bundler's API, a runtime dependency on Bundler would be required. However, introducing such a dependency solely for the sake of using Perhaps continuing to resolve this with regexp would be a more appropriate approach. In other words, it might be better if this change were not made. |
Hey @koic, did you mean #12186? This "Replace regex with
@koic For this change on its own, I would agree. But the real benefit here is new |
I agree it's not prudent to add a runtime dependency on Bundler, so I see three paths ahead:
|
@bbatsov You raise an interesting point, I'll think on it! In the mean time, could I get your thoughts on this feature request and the implementation I proposed for it? Is the |
Just ran into this, apparently this is already used by RuboCop rubocop/lib/rubocop/lockfile.rb Lines 30 to 38 in a455e9d
|
Ah, excellent - so I guess you know how to proceed now. :-) |
@amomchilov Any updates here? |
Hey @bbatsov I had a question about how to proceed. Imessaged you in the RuboCop discord (I figured that was a good spot, because it showed you as online). Cross posting: Добър вечер @bbatsov ! I'm taking a look at using the They both do some directory traversal to find a gemfile in a parent dir, if it's not found in the cwd. Not sure if they're exactly the same, though 🤔 I'm not sure how to proceed. Do you think I should modify |
I'd be fine with both approaches, but the first one sounds slightly better to me. |
3e61208
to
fa6689f
Compare
@bbatsov Can we move the lock-file parsing related discussion to the underlying PR? That's what introduces that logic, it's an impl detail separate from the changes in this PR. I responded here: #12186 (review) |
3eaa47d
to
f518980
Compare
I guess you can rebase this one now that #12186 is finally merged. |
f518980
to
53c1178
Compare
@bbatsov Rebased, and ready to merge! Thanks for jumping in to merge all these pieces :) |
Depends on #12186, see the difference: amomchilov/rubocop@add-requires_gem-api...parse-lockfile-with-bundler
Now that we have a Hash of all of the target's gems, we can just use that
target_rails_version_from_bundler_lock_file
, and remove the manual regex parsing.Before submitting the PR make sure the following are checked:
Commit message starts with[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).Added tests.bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.