Skip to content

Commit

Permalink
Relax rubocop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
feelepxyz committed Dec 20, 2019
1 parent 5cdc80e commit 08c679d
Show file tree
Hide file tree
Showing 56 changed files with 86 additions and 187 deletions.
18 changes: 10 additions & 8 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,35 @@ AllCops:
- '*/vendor/**/*'
- '*/bin/**/*'
- '*/tmp/**/*'
- 'tmp/**/*'
- '*/helpers/**/*'

Layout/DotPosition:
EnforcedStyle: trailing

Layout/LineLength:
Max: 80

Layout/RescueEnsureAlignment:
Enabled: false

Metrics/ClassLength:
Max: 250
Max: 350

Metrics/ModuleLength:
Max: 200
Max: 350

Metrics/CyclomaticComplexity:
Max: 7

Metrics/LineLength:
Max: 80
Max: 10

Metrics/AbcSize:
Max: 30
Max: 35

Metrics/MethodLength:
Max: 25
Max: 35

Metrics/BlockLength:
Max: 35
Exclude:
- '*/Rakefile'
- '*/spec/**/*'
Expand Down
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace :ci do
end
end

# rubocop:disable Metrics/BlockLength
namespace :gems do
task build: :clean do
root_path = Dir.getwd
Expand Down Expand Up @@ -89,8 +90,8 @@ namespace :gems do
begin
sh "gem push #{gem_path}"
break
rescue => err
puts "! `gem push` failed with error: #{err}"
rescue StandardError => e
puts "! `gem push` failed with error: #{e}"
raise if attempts >= 3
end
end
Expand Down Expand Up @@ -125,7 +126,6 @@ def rubygems_release_exists?(name, version)
existing_versions.include?(version)
end

# rubocop:disable Metrics/MethodLength
def changed_packages
all_packages = GEMSPECS.
select { |gs| gs.include?("/") }.
Expand Down Expand Up @@ -163,9 +163,9 @@ def changed_packages

packages
end
# rubocop:enable Metrics/MethodLength

def commit_range_changes_paths?(range, paths)
cmd = %w(git diff --quiet) + [range, "--"] + paths
!system(Shellwords.join(cmd))
end
# rubocop:enable Metrics/BlockLength
48 changes: 36 additions & 12 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
# - docker
# - terraform

# rubocop:disable Style/GlobalVars

$LOAD_PATH << "./bundler/lib"
$LOAD_PATH << "./cargo/lib"
$LOAD_PATH << "./common/lib"
Expand Down Expand Up @@ -110,7 +112,8 @@

unless ENV["LOCAL_CONFIG_VARIABLES"].to_s.strip.empty?
# For example:
# "[{\"type\":\"npm_registry\",\"registry\":\"registry.npmjs.org\",\"token\":\"123\"}]"
# "[{\"type\":\"npm_registry\",\"registry\":\
# "registry.npmjs.org\",\"token\":\"123\"}]"
$options[:credentials].concat(JSON.parse(ENV["LOCAL_CONFIG_VARIABLES"]))
end

Expand All @@ -133,17 +136,17 @@
$options[:cache_steps].concat(value.split(",").map(&:strip))
end

opts.on("--write", "Write the update to the cache directory") do |value|
opts.on("--write", "Write the update to the cache directory") do |_value|
$options[:write] = true
end

opts.on("--lockfile-only", "Only update the lockfile") do |value|
$options[:lockfile_only] = value
end

opts_req_description = "Options: auto, widen_ranges, bump_versions or "\
opts_req_desc = "Options: auto, widen_ranges, bump_versions or "\
"bump_versions_if_necessary"
opts.on("--requirements-update-strategy STRATEGY", opts_req_description) do |value|
opts.on("--requirements-update-strategy STRATEGY", opts_req_desc) do |value|
value = nil if value == "auto"
$options[:requirements_update_strategy] = value
end
Expand Down Expand Up @@ -193,8 +196,11 @@ def cached_read(name)
cache_dir = File.dirname(cache_path)
FileUtils.mkdir_p(cache_dir) unless Dir.exist?(cache_dir)
cached = File.read(cache_path) if File.exist?(cache_path)
# rubocop:disable Security/MarshalLoad
return Marshal.load(cached) if cached

# rubocop:enable Security/MarshalLoad

data = yield
File.write(cache_path, Marshal.dump(data))
data
Expand All @@ -206,15 +212,23 @@ def dependency_files_cache_dir
File.join("dry-run", $repo_name.split("/"), branch, dir)
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def cached_dependency_files_read
cache_dir = dependency_files_cache_dir
cache_manifest_path = File.join(cache_dir, "cache-manifest-#{$package_manager}.json")
cache_manifest_path = File.join(
cache_dir, "cache-manifest-#{$package_manager}.json"
)
FileUtils.mkdir_p(cache_dir) unless Dir.exist?(cache_dir)

cached_manifest = File.read(cache_manifest_path) if File.exist?(cache_manifest_path)
if File.exist?(cache_manifest_path)
cached_manifest = File.read(cache_manifest_path)
end
cached_dependency_files = JSON.parse(cached_manifest) if cached_manifest

all_files_cached = cached_dependency_files && cached_dependency_files.all? do |file|
all_files_cached = cached_dependency_files&.all? do |file|
File.exist?(File.join(cache_dir, file["name"]))
end

Expand Down Expand Up @@ -267,6 +281,10 @@ def cached_dependency_files_read
data
end
end
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize

source = Dependabot::Source.new(
provider: "github",
Expand All @@ -278,7 +296,7 @@ def cached_dependency_files_read

$files = cached_dependency_files_read do
fetcher = Dependabot::FileFetchers.for_package_manager($package_manager).
new(source: source, credentials: $options[:credentials])
new(source: source, credentials: $options[:credentials])
fetcher.files
end

Expand All @@ -305,7 +323,7 @@ def update_checker_for(dependency)
credentials: $options[:credentials],
requirements_update_strategy: $options[:requirements_update_strategy],
ignored_versions: ignore_conditions_for(dependency),
security_advisories: security_advisories_for(dependency),
security_advisories: security_advisories_for(dependency)
)
end

Expand Down Expand Up @@ -347,7 +365,7 @@ def peer_dependencies_can_update?(checker, reqs_to_unlock)
name: dep.name,
version: dep.previous_version,
requirements: dep.previous_requirements,
package_manager: dep.package_manager,
package_manager: dep.package_manager
)
update_checker_for(original_peer_dep).
can_update?(requirements_to_unlock: :own)
Expand Down Expand Up @@ -379,6 +397,7 @@ def generate_dependency_files_for(updated_dependencies)

puts "=> updating #{dependencies.count} dependencies"

# rubocop:disable Metrics/BlockLength
dependencies.each do |dep|
puts "\n=== #{dep.name} (#{dep.version})"
checker = update_checker_for(dep)
Expand All @@ -405,7 +424,8 @@ def generate_dependency_files_for(updated_dependencies)
puts " => requirements to unlock: #{requirements_to_unlock}"

if checker.respond_to?(:requirements_update_strategy)
puts " => requirements update strategy: #{checker.requirements_update_strategy}"
puts " => requirements update strategy: "\
"#{checker.requirements_update_strategy}"
end

if requirements_to_unlock == :update_not_possible
Expand All @@ -423,8 +443,9 @@ def generate_dependency_files_for(updated_dependencies)
end

updated_files = generate_dependency_files_for(updated_deps)

# Currently unused but used to create pull requests (from the updater)
updated_deps = updated_deps.reject do |d|
updated_deps.reject do |d|
next false if d.name == checker.dependency.name
next true if d.requirements == d.previous_requirements

Expand All @@ -444,3 +465,6 @@ def generate_dependency_files_for(updated_dependencies)
show_diff(original_file, updated_file)
end
end
# rubocop:enable Metrics/BlockLength

# rubocop:enable Style/GlobalVars
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
require "dependabot/errors"
require "dependabot/bundler/file_updater"
require "dependabot/git_commit_checker"

# rubocop:disable Metrics/ClassLength
module Dependabot
module Bundler
class FileUpdater
Expand Down Expand Up @@ -458,4 +456,3 @@ def using_bundler_2?
end
end
end
# rubocop:enable Metrics/ClassLength
3 changes: 0 additions & 3 deletions bundler/lib/dependabot/bundler/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
require "dependabot/bundler/file_updater/requirement_replacer"
require "dependabot/bundler/version"
require "dependabot/git_commit_checker"

# rubocop:disable Metrics/ClassLength
module Dependabot
module Bundler
class UpdateChecker < Dependabot::UpdateCheckers::Base
Expand Down Expand Up @@ -389,7 +387,6 @@ def prepared_dependency_files(remove_git_source:, unlock_requirement:,
end
end
end
# rubocop:enable Metrics/ClassLength

Dependabot::UpdateCheckers.
register("bundler", Dependabot::Bundler::UpdateChecker)
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def at_same_precision(new_version, old_version)
end

# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def update_gemspec_requirement(req)
req = req.merge(source: updated_source) if req.fetch(:source)
return req unless latest_version && latest_resolvable_version
Expand All @@ -153,7 +152,6 @@ def update_gemspec_requirement(req)
req.merge(requirement: :unfixable)
end
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity

def requirement_satisfied?(req, groups)
if groups == ["development"]
Expand Down Expand Up @@ -216,7 +214,6 @@ def bumped_requirements(req)
end
end

# rubocop:disable Metrics/AbcSize
def convert_twidle_to_range(requirement, version_to_be_permitted)
version = requirement.requirements.first.last
version = version.release if version.prerelease?
Expand Down Expand Up @@ -245,7 +242,6 @@ def convert_twidle_to_range(requirement, version_to_be_permitted)
Gem::Requirement.new("< #{ub_segments.join('.')}")
]
end
# rubocop:enable Metrics/AbcSize

# Updates the version in a "~>" constraint to allow the given version
def update_twiddle_version(requirement, version_to_be_permitted)
Expand All @@ -256,7 +252,6 @@ def update_twiddle_version(requirement, version_to_be_permitted)

# Updates the version in a "<" or "<=" constraint to allow the given
# version
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/PerceivedComplexity
def update_greatest_version(requirement, version_to_be_permitted)
if version_to_be_permitted.is_a?(String)
Expand All @@ -283,7 +278,7 @@ def update_greatest_version(requirement, version_to_be_permitted)

Gem::Requirement.new("#{op} #{new_segments.join('.')}")
end
# rubocop:enable Metrics/AbcSize

# rubocop:enable Metrics/PerceivedComplexity
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def regenerate_dependency_files_without_ruby_lock
).prepared_dependency_files
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def dependency_from_definition(unlock_subdependencies: true)
dependencies_to_unlock = [dependency.name]
Expand All @@ -181,7 +180,7 @@ def dependency_from_definition(unlock_subdependencies: true)
# try again but without unlocking any other sub-dependencies
dependency_from_definition(unlock_subdependencies: false)
end
# rubocop:enable Metrics/CyclomaticComplexity

# rubocop:enable Metrics/PerceivedComplexity

def unlock_yanked_gem(dependencies_to_unlock, error)
Expand Down
6 changes: 2 additions & 4 deletions cargo/lib/dependabot/cargo/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def fetch_workspace_files(file:, previously_fetched_files:)
files
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def fetch_path_dependency_files(file:, previously_fetched_files:)
current_dir = file.name.rpartition("/").first
Expand Down Expand Up @@ -133,7 +132,7 @@ def fetch_path_dependency_files(file:, previously_fetched_files:)
raise Dependabot::PathDependenciesNotReachable,
unfetchable_required_path_deps
end
# rubocop:enable Metrics/CyclomaticComplexity

# rubocop:enable Metrics/PerceivedComplexity

def path_dependency_paths_from_file(file)
Expand Down Expand Up @@ -217,7 +216,6 @@ def workspace_dependency_paths_from_file(file)

# Check whether a path is required or not. It will not be required if
# an alternative source (i.e., a git source) is also specified
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def required_path?(file, path)
Expand Down Expand Up @@ -256,7 +254,7 @@ def required_path?(file, path)

false
end
# rubocop:enable Metrics/AbcSize

# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

Expand Down
8 changes: 1 addition & 7 deletions cargo/lib/dependabot/cargo/file_updater/lockfile_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
require "dependabot/cargo/file_updater/manifest_updater"
require "dependabot/cargo/file_parser"
require "dependabot/shared_helpers"

# rubocop:disable Metrics/ClassLength
module Dependabot
module Cargo
class FileUpdater
Expand Down Expand Up @@ -68,8 +66,6 @@ def handle_cargo_error(error)
raise Dependabot::DependencyFileNotResolvable, error.message
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def better_specification_needed?(error)
return false if @custom_specification
Expand Down Expand Up @@ -99,8 +95,7 @@ def better_specification_needed?(error)
@custom_specification = spec_options.first
true
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity

# rubocop:enable Metrics/PerceivedComplexity

def dependency_spec
Expand Down Expand Up @@ -378,4 +373,3 @@ def virtual_manifest?(file)
end
end
end
# rubocop:enable Metrics/ClassLength
Loading

0 comments on commit 08c679d

Please sign in to comment.