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

Update rubocop dependency to < 2.0 #8

Merged
merged 11 commits into from Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/rubocop/cop/netlify/invalid_model_assignment.rb
Expand Up @@ -13,7 +13,6 @@ module Netlify
# form.email = "bettse@netlify.com"
class InvalidModelAssignment < Cop
MSG = "Assigning to `attributes` will not update record"
RESTRICT_ON_SEND = [:attributes].freeze

def_node_matcher :assign_attributes?, <<~PATTERN
(send (send (...) :attributes) :[]= _ _)
Expand Down
2 changes: 1 addition & 1 deletion rubocop-netlify.gemspec
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")

spec.add_dependency "rubocop", "~> 0.72", "< 0.83"
spec.add_dependency "rubocop", "~> 0.72", "< 2.0"
spec.add_development_dependency "minitest", "~> 5.10"

# Specify which files should be added to the gem when it is released.
Expand Down
9 changes: 4 additions & 5 deletions test/assertion_helper.rb
Expand Up @@ -3,7 +3,6 @@
# Copied and adapted from:
# https://github.com/rubocop-hq/rubocop-minitest/blob/v0.8.1/test/assertion_helper.rb
#
#
# ===========
#
#
Expand Down Expand Up @@ -70,10 +69,10 @@ def inspect_source(source, cop, file = nil)
end

def investigate(cop, processed_source)
forces = RuboCop::Cop::Force.all.each_with_object([]) do |klass, instances|
next unless cop.join_force?(klass)

instances << klass.new([cop])
needed = Hash.new { |h, k| h[k] = [] }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm... not sure why this is needed to be defined like this (v.s. needed = Hash.new) 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! It's another Ruby nicety

This creates a hash where the default value is a new hash (new as in new every time, not the same array as it'd happen with Hash.new([]))
This allows to use << in the line below without having to initialize each needed[x] every time.

More details:

Array(cop.class.joining_forces).each { |force| needed[force] << cop }
forces = needed.map do |force_class, joining_cops|
force_class.new(joining_cops)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you comment more on why you needed to make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, sorry! I thought it was in a commit comment but I missed it.

Change was introduced in rubocop/rubocop@f8813e7 on v0.87. Details are vague, because it's a big commit/PR, but it removes the join_force? method in favor of joining_forces)

Upgrade notes:
https://github.com/rubocop/rubocop/blob/3482522e2be022eee2321722f4e049ab4bcb3bf1/docs/modules/ROOT/pages/v1_upgrade_notes.adoc#joining-forces

In reality, I just copy-pasted the updated version from https://github.com/rubocop/rubocop-minitest/blob/v0.11.0/test/assertion_helper.rb (As noted in the top of this file, the entire file is copied from there)

end

commissioner = RuboCop::Cop::Commissioner.new([cop], forces, raise_error: true)
Expand Down