Skip to content

Commit

Permalink
Merge pull request #2726 from dependabot/jurre/longer-lines
Browse files Browse the repository at this point in the history
Adjust rubocop max line length to 120
  • Loading branch information
jurre authored Nov 5, 2020
2 parents e9a7893 + b7c25bc commit ab4fb10
Show file tree
Hide file tree
Showing 122 changed files with 259 additions and 753 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Layout/EmptyLinesAroundAttributeAccessor:
Enabled: false

Layout/LineLength:
Max: 80
Max: 120

Layout/RescueEnsureAlignment:
Enabled: false
Expand Down
8 changes: 2 additions & 6 deletions bundler/lib/dependabot/bundler/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class FileFetcher < Dependabot::FileFetchers::Base
require "dependabot/bundler/file_fetcher/require_relative_finder"

def self.required_files_in?(filenames)
if filenames.any? { |name| name.match?(%r{^[^/]*\.gemspec$}) }
return true
end
return true if filenames.any? { |name| name.match?(%r{^[^/]*\.gemspec$}) }

filenames.include?("Gemfile") || filenames.include?("gems.rb")
end
Expand Down Expand Up @@ -133,9 +131,7 @@ def path_gemspecs
unfetchable_gems << path.basename.to_s
end

if unfetchable_gems.any?
raise Dependabot::PathDependenciesNotReachable, unfetchable_gems
end
raise Dependabot::PathDependenciesNotReachable, unfetchable_gems if unfetchable_gems.any?

gemspec_files.tap { |ar| ar.each { |f| f.support_file = true } }
end
Expand Down
4 changes: 1 addition & 3 deletions bundler/lib/dependabot/bundler/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ def dependency_version(dependency_name)

# If the source is Git we're better off knowing the SHA-1 than the
# version.
if spec.source.instance_of?(::Bundler::Source::Git)
return spec.source.revision
end
return spec.source.revision if spec.source.instance_of?(::Bundler::Source::Git)

spec.version
end
Expand Down
4 changes: 1 addition & 3 deletions bundler/lib/dependabot/bundler/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def vendor_updater
def check_required_files
file_names = dependency_files.map(&:name)

if lockfile && !gemfile
raise "A Gemfile must be provided if a lockfile is!"
end
raise "A Gemfile must be provided if a lockfile is!" if lockfile && !gemfile

return if file_names.any? { |name| name.match?(%r{^[^/]*\.gemspec$}) }
return if gemfile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ def updated_gemfile_content
content
)

if remove_git_source?(dependency)
content = remove_gemfile_git_source(dependency, content)
end
content = remove_gemfile_git_source(dependency, content) if remove_git_source?(dependency)

if update_git_pin?(dependency)
content = update_gemfile_git_pin(dependency, gemfile, content)
end
content = update_gemfile_git_pin(dependency, gemfile, content) if update_git_pin?(dependency)
end

content
Expand Down
16 changes: 4 additions & 12 deletions bundler/lib/dependabot/bundler/file_updater/gemspec_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,15 @@ def wrap_require(node)
def replace_version_assignments(node)
return unless node.is_a?(Parser::AST::Node)

if node_assigns_to_version_constant?(node)
return replace_constant(node)
end
return replace_constant(node) if node_assigns_to_version_constant?(node)

node.children.each { |child| replace_version_assignments(child) }
end

def replace_version_constant_references(node)
return unless node.is_a?(Parser::AST::Node)

if node_is_version_constant?(node)
return replace(node.loc.expression, %("#{replacement_version}"))
end
return replace(node.loc.expression, %("#{replacement_version}")) if node_is_version_constant?(node)

node.children.each do |child|
replace_version_constant_references(child)
Expand All @@ -122,19 +118,15 @@ def replace_version_constant_references(node)
def replace_file_assignments(node)
return unless node.is_a?(Parser::AST::Node)

if node_assigns_files_to_var?(node)
return replace_file_assignment(node)
end
return replace_file_assignment(node) if node_assigns_files_to_var?(node)

node.children.each { |child| replace_file_assignments(child) }
end

def replace_require_paths_assignments(node)
return unless node.is_a?(Parser::AST::Node)

if node_assigns_require_paths?(node)
return replace_require_paths_assignment(node)
end
return replace_require_paths_assignment(node) if node_assigns_require_paths?(node)

node.children.each do |child|
replace_require_paths_assignments(child)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def updated_lockfile_content
begin
updated_content = build_updated_lockfile

if lockfile.content == updated_content
raise "Expected content to change!"
end
raise "Expected content to change!" if lockfile.content == updated_content

updated_content
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def update_comment_spacing_if_required(content, updated_content)
end

def length_change
unless previous_requirement.start_with?("=")
return updated_requirement.length - previous_requirement.length
end
return updated_requirement.length - previous_requirement.length unless previous_requirement.start_with?("=")

updated_requirement.length -
previous_requirement.gsub(/^=/, "").strip.length
Expand Down Expand Up @@ -205,9 +203,7 @@ def serialized_req(req, use_equality_operator)
# Gem::Requirement serializes exact matches as a string starting
# with `=`. We may need to remove that equality operator if it
# wasn't used originally.
unless use_equality_operator
tmp_req = tmp_req.gsub(/(?<![<>])=/, "")
end
tmp_req = tmp_req.gsub(/(?<![<>])=/, "") unless use_equality_operator

tmp_req.strip
end
Expand Down
8 changes: 2 additions & 6 deletions bundler/lib/dependabot/bundler/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def changelog_url_from_gemspec_download
# Note: This response MUST NOT be unmarshalled
# (as calling Marshal.load is unsafe)
def rubygems_marshalled_gemspec_response
if defined?(@rubygems_marshalled_gemspec_response)
return @rubygems_marshalled_gemspec_response
end
return @rubygems_marshalled_gemspec_response if defined?(@rubygems_marshalled_gemspec_response)

gemspec_uri =
"#{registry_url}quick/Marshal.4.8/"\
Expand All @@ -135,9 +133,7 @@ def rubygems_marshalled_gemspec_response
**SharedHelpers.excon_defaults(headers: registry_auth_headers)
)

if response.status >= 400
return @rubygems_marshalled_gemspec_response = nil
end
return @rubygems_marshalled_gemspec_response = nil if response.status >= 400

@rubygems_marshalled_gemspec_response =
Zlib::Inflate.inflate(response.body)
Expand Down
16 changes: 4 additions & 12 deletions bundler/lib/dependabot/bundler/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ def requirements_unlocked_or_can_be?

def requirements_update_strategy
# If passed in as an option (in the base class) honour that option
if @requirements_update_strategy
return @requirements_update_strategy.to_sym
end
return @requirements_update_strategy.to_sym if @requirements_update_strategy

# Otherwise, widen ranges for libraries and bump versions for apps
dependency.version.nil? ? :bump_versions_if_necessary : :bump_versions
Expand Down Expand Up @@ -142,9 +140,7 @@ def updated_dependencies_after_full_unlock
end

def preferred_resolvable_version_details
if vulnerable?
return { version: lowest_resolvable_security_fix_version }
end
return { version: lowest_resolvable_security_fix_version } if vulnerable?

latest_resolvable_version_details
end
Expand Down Expand Up @@ -220,9 +216,7 @@ def latest_version_for_git_dependency

# Otherwise, if the gem isn't pinned, the latest version is just the
# latest commit for the specified branch.
unless git_commit_checker.pinned?
return git_commit_checker.head_commit_for_current_branch
end
return git_commit_checker.head_commit_for_current_branch unless git_commit_checker.pinned?

# If the dependency is pinned to a tag that looks like a version then
# we want to update that tag. The latest version will then be the SHA
Expand All @@ -246,9 +240,7 @@ def latest_resolvable_version_for_git_dependency

# Otherwise, if the gem isn't pinned, the latest version is just the
# latest commit for the specified branch.
unless git_commit_checker.pinned?
return latest_resolvable_commit_with_unchanged_git_source
end
return latest_resolvable_commit_with_unchanged_git_source unless git_commit_checker.pinned?

# If the dependency is pinned to a tag that looks like a version then
# we want to update that tag. The latest version will then be the SHA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ def updated_version_requirement_string(filename)
lower_bound_req = updated_version_req_lower_bound(filename)

return lower_bound_req if latest_allowable_version.nil?
unless Gem::Version.correct?(latest_allowable_version)
return lower_bound_req
end
return lower_bound_req unless Gem::Version.correct?(latest_allowable_version)

lower_bound_req + ", <= #{latest_allowable_version}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def lowest_security_fix_version
:credentials, :ignored_versions, :security_advisories

def fetch_latest_version_details
if dependency_source.git?
return dependency_source.latest_git_version_details
end
return dependency_source.latest_git_version_details if dependency_source.git?

relevant_versions = dependency_source.versions
relevant_versions = filter_prerelease_versions(relevant_versions)
Expand Down Expand Up @@ -71,9 +69,7 @@ def filter_prerelease_versions(versions_array)
def filter_ignored_versions(versions_array)
filtered = versions_array.
reject { |v| ignore_reqs.any? { |r| r.satisfied_by?(v) } }
if @raise_on_ignored && filtered.empty? && versions_array.any?
raise AllVersionsIgnored
end
raise AllVersionsIgnored if @raise_on_ignored && filtered.empty? && versions_array.any?

filtered
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def convert_twidle_to_range(requirement, version_to_be_permitted)
lb_segments = version.segments
lb_segments.pop while lb_segments.any? && lb_segments.last.zero?

if lb_segments.none?
return [Gem::Requirement.new("< #{ub_segments.join('.')}")]
end
return [Gem::Requirement.new("< #{ub_segments.join('.')}")] if lb_segments.none?

# Ensure versions have the same length as each other (cosmetic)
length = [lb_segments.count, ub_segments.count].max
Expand All @@ -253,9 +251,7 @@ def update_twiddle_version(requirement, version_to_be_permitted)
# Updates the version in a "<" or "<=" constraint to allow the given
# version
def update_greatest_version(requirement, version_to_be_permitted)
if version_to_be_permitted.is_a?(String)
version_to_be_permitted = Gem::Version.new(version_to_be_permitted)
end
version_to_be_permitted = Gem::Version.new(version_to_be_permitted) if version_to_be_permitted.is_a?(String)
op, version = requirement.requirements.first
version = version.release if version.prerelease?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def in_a_native_bundler_context(error_handling: true)
rescue SharedHelpers::HelperSubprocessFailed => e
retry_count ||= 0
retry_count += 1
if retryable_error?(e) && retry_count <= 2
sleep(rand(1.0..5.0)) && retry
end
sleep(rand(1.0..5.0)) && retry if retryable_error?(e) && retry_count <= 2

error_handling ? handle_bundler_errors(e) : raise
end
Expand All @@ -70,9 +68,7 @@ def retryable_error?(error)
return true if error.error_class == "JSON::ParserError"
return true if RETRYABLE_ERRORS.include?(error.error_class)

unless RETRYABLE_PRIVATE_REGISTRY_ERRORS.include?(error.error_class)
return false
end
return false unless RETRYABLE_PRIVATE_REGISTRY_ERRORS.include?(error.error_class)

private_registry_credentials.any?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def fetch_latest_resolvable_version_details
# rubocop:enable Metrics/PerceivedComplexity

def circular_dependency_at_new_version?(error)
unless error.error_class.include?("CyclicDependencyError")
return false
end
return false unless error.error_class.include?("CyclicDependencyError")

error.message.include?("'#{dependency.name}'")
end
Expand Down Expand Up @@ -171,9 +169,7 @@ def latest_version_details

def ruby_version_incompatible?(details)
# It's only the old index we have a problem with
unless details[:fetcher] == "Bundler::Fetcher::Dependency"
return false
end
return false unless details[:fetcher] == "Bundler::Fetcher::Dependency"

# If no Ruby version is specified, we don't have a problem
return false unless details[:ruby_version]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@

its([:version]) { is_expected.to eq(Gem::Version.new("0.7.0")) }

# rubocop:disable Layout/LineLength
# TODO: https://github.com/dependabot/dependabot-core/issues/2364
# context "that will be removed if other sub-dependencies are updated" do
# let(:gemfile_fixture_name) { "subdependency_change" }
Expand All @@ -123,7 +122,6 @@
# expect(subject.version).to eq(Gem::Version.new("1.10.9"))
# end
# end
# rubocop:enable Layout/LineLength
end

context "with a Bundler version specified" do
Expand Down
4 changes: 1 addition & 3 deletions bundler/spec/native_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
before do
File.write(File.join(tmp_path, gemfile_name), gemfile_fixture)

if lockfile_fixture_name
File.write(File.join(tmp_path, lockfile_name), lockfile_fixture)
end
File.write(File.join(tmp_path, lockfile_name), lockfile_fixture) if lockfile_fixture_name
end

def in_tmp_folder(&block)
Expand Down
20 changes: 5 additions & 15 deletions cargo/lib/dependabot/cargo/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,22 @@ def requirement_from_declaration(declaration)
if declaration.is_a?(String)
return declaration == "" ? nil : declaration
end
unless declaration.is_a?(Hash)
raise "Unexpected dependency declaration: #{declaration}"
end
if declaration["version"]&.is_a?(String) && declaration["version"] != ""
return declaration["version"]
end
raise "Unexpected dependency declaration: #{declaration}" unless declaration.is_a?(Hash)
return declaration["version"] if declaration["version"]&.is_a?(String) && declaration["version"] != ""

nil
end

def name_from_declaration(name, declaration)
return name if declaration.is_a?(String)
unless declaration.is_a?(Hash)
raise "Unexpected dependency declaration: #{declaration}"
end
raise "Unexpected dependency declaration: #{declaration}" unless declaration.is_a?(Hash)

declaration.fetch("package", name)
end

def source_from_declaration(declaration)
return if declaration.is_a?(String)
unless declaration.is_a?(Hash)
raise "Unexpected dependency declaration: #{declaration}"
end
raise "Unexpected dependency declaration: #{declaration}" unless declaration.is_a?(Hash)

return git_source_details(declaration) if declaration["git"]
return { type: "path" } if declaration["path"]
Expand Down Expand Up @@ -203,9 +195,7 @@ def git_source_details(declaration)
end

def version_from_lockfile_details(package_details)
unless package_details["source"]&.start_with?("git+")
return package_details["version"]
end
return package_details["version"] unless package_details["source"]&.start_with?("git+")

package_details["source"].split("#").last
end
Expand Down
Loading

0 comments on commit ab4fb10

Please sign in to comment.