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

[Fix #9803] Fix Bundler/GemVersion cop not respecting git tags #9807

Closed
wants to merge 1 commit into from

Conversation

tejasbubane
Copy link
Contributor

Closes #9803


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@dvandersluis
Copy link
Member

Can you add a test that uses git: instead of github?

Also I wonder if git/github with a branch key should be accepted too?

@tejasbubane
Copy link
Contributor Author

tejasbubane commented May 17, 2021

@dvandersluis

Can you add a test that uses git: instead of github?

Added specs with git and github both.

Also I wonder if git/github with a branch key should be accepted too?

I don't think so. Tags are usually fixed. Branch reference keeps changing, so it is not really fixing a version.

(send nil? :gem <(str #version_specification?) ...>)
(send nil? :gem
<{(str #version_specification?)
(hash <(pair (sym :tag) (str _)) (pair (sym {:git :github}) (str _)) ...>)} ...>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is matching git or github required? Would (sym :tag) be enough to indicate tag presence? That way the cop doesn't need to be concerned about the gem source.

If it is needed, it looks like bitbucket is also a valid option to provide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not want this to report false positives - hence the extra check.

Thanks I was not aware of the bitbucket option. Looks like there is gist as well. I'll add them both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added bitbucket only, not sure if gist allows versions. I mean it has revisions, but the gist ID remains same.

Copy link
Member

Choose a reason for hiding this comment

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

Users can also add their own arbitrary git sources using git_source so we should probably handle that as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dvandersluis I think this might be tricky given that we can define custom sources:

git_source(:stash) { |repo_name| "https://stash.corp.acme.pl/#{repo_name}.git" }
...
gem 'rails', :stash => 'forks/rails'

Copy link
Member

Choose a reason for hiding this comment

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

I agree it's tricky, but if we don't handle it someway it leads to false reporting (which is maybe another argument for just looking for tag/ref/etc. and not caring about the other keys).

gem 'rubocop', github: 'rubocop/rubocop', tag: 'v1'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Gem version specification is forbidden.
gem 'rubocop', git: 'https://github.com/rubocop/rubocop', tag: 'v1'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Gem version specification is forbidden.
Copy link
Member

@koic koic May 17, 2021

Choose a reason for hiding this comment

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

These look strange. If :tag or :ref is specified with :git or :github, it's likely that a meaningful version of commit is being used. So, shouldn't these cases always be accepted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for 'EnforcedStyle' => 'forbidden' which forbids fixing a gem version (or in this case an equivalent git tag).

Copy link
Member

Choose a reason for hiding this comment

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

Practically, if :tag or :ref with :git or :github is used, the pinned value should be respected. AFAIK, even 'EnforcedStyle' => 'forbidden' should not be forbidden, as it is used for intentional forks and the like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@@ -24,6 +26,9 @@
gem 'rubocop', '~> 1'
gem 'rubocop', '~> 1.12', require: false
gem 'rubocop', '>= 1.5.0', '< 1.10.0', git: 'https://github.com/rubocop/rubocop'
gem 'rubocop', github: 'rubocop/rubocop', tag: 'v1'
gem 'rubocop', git: 'https://github.com/rubocop/rubocop', tag: 'v1'
gem 'rubocop', bitbucket: 'https://bitbucket.com/foo/bar', tag: 'v1'
Copy link
Member

Choose a reason for hiding this comment

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

:ref can be accepted as well as :tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@tejasbubane tejasbubane force-pushed the fix-9803 branch 2 times, most recently from 4f52656 to de955d1 Compare May 18, 2021 17:59
@bbatsov
Copy link
Collaborator

bbatsov commented May 27, 2021

Two bits of feedback from me:

  • Do we really need so many matchers? After all it seems to me we only care for the presence of :tag and :ref, as it's unlikely someone would use them without some VCS reference.
  • The examples need to be updated to reflect the support for :tag and :ref.

@@ -45,6 +45,21 @@ class GemVersion < Base
(send nil? :gem <(str #version_specification?) ...>)
PATTERN

# @!method with_git_ref?(node)
def_node_matcher :with_git_ref?, <<~PATTERN
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd use a more neutral name here - e.g. commit_ref?.

PATTERN

# @!method git?(node)
def_node_matcher :git?, <<~PATTERN
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need to change for the VCS? I doubt someone would use :tag or :ref without them and this will probably result in some mistake. Haven't tried it, though.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 10, 2021

@tejasbubane ping :-)

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 25, 2021

Superseded by #9885.

@bbatsov bbatsov closed this Jun 25, 2021
@tejasbubane tejasbubane deleted the fix-9803 branch June 26, 2021 15:51
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

Successfully merging this pull request may close these issues.

Bundler/GemVersion not respecting tags
5 participants