diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-10-15 15:11:28 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-10-16 10:14:41 +0300 |
commit | c48af5036c44b2ba175088deae83237c8321f5f6 (patch) | |
tree | 647d5fbc9a32d2ad15b485c69c2738fe613a528b | |
parent | 89c4bed7ce9abaa4431c9c28905535cd4c402971 (diff) |
Enable some cops
To make Rubocop on CI somewhat useful, it has been enabled with some
cops, using the `--auto-correct` flag.
34 files changed, 82 insertions, 346 deletions
diff --git a/ruby/.rubocop.yml b/ruby/.rubocop.yml index 3ffe2b0d8..280287d16 100644 --- a/ruby/.rubocop.yml +++ b/ruby/.rubocop.yml @@ -1,2 +1,4 @@ inherit_from: .rubocop_todo.yml +Style/NumericPredicate: + Enabled: false diff --git a/ruby/.rubocop_todo.yml b/ruby/.rubocop_todo.yml index 24f6ec1dc..856c4a165 100644 --- a/ruby/.rubocop_todo.yml +++ b/ruby/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-10-15 16:28:48 +0200 using RuboCop version 0.54.0. +# on 2018-10-15 16:35:26 +0200 using RuboCop version 0.54.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -14,82 +14,6 @@ Bundler/OrderedGems: Exclude: - 'Gemfile' -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth. -# SupportedStyles: case, end -Layout/CaseIndentation: - Exclude: - - 'lib/gitaly_server/repository_service.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'lib/gitlab/git/gitlab_projects.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'lib/gitlab/git/gitlab_projects.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Layout/EndAlignment: - Exclude: - - 'lib/gitaly_server/repository_service.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'spec/lib/gitlab/version_info_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Width, IgnoredPatterns. -Layout/IndentationWidth: - Exclude: - - 'lib/gitlab/git/wiki_page.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/gitaly_server/utils.rb' - - 'lib/gitlab/gollum.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'spec/lib/gitaly_server/rugged_interceptor_spec.rb' - - 'spec/lib/gitlab/version_info_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingBlankLines: - Exclude: - - 'lib/gitlab/git/gitlab_projects.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/TrailingWhitespace: - Exclude: - - 'spec/integration_helper.rb' - # Offense count: 1 Lint/AmbiguousBlockAssociation: Exclude: @@ -107,14 +31,6 @@ Lint/AssignmentInCondition: - 'lib/gitlab/git/repository.rb' - 'lib/gitlab/version_info.rb' -# Offense count: 6 -Lint/DuplicateMethods: - Exclude: - - 'lib/gitlab/git/blob.rb' - - 'lib/gitlab/git/gitlab_projects.rb' - - 'lib/gitlab/git/repository.rb' - - 'lib/gitlab/git/wiki_page.rb' - # Offense count: 7 Lint/HandleExceptions: Exclude: @@ -125,16 +41,6 @@ Lint/HandleExceptions: - 'lib/gitlab/git/repository_mirroring.rb' - 'spec/lib/gitlab/git/popen_spec.rb' -# Offense count: 5 -# Configuration parameters: MaximumRangeSize. -Lint/MissingCopEnableDirective: - Exclude: - - 'lib/gitaly_server/exception_sanitizer_interceptor.rb' - - 'lib/gitaly_server/sentry_interceptor.rb' - - 'spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb' - - 'spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb' - - 'spec/lib/gitaly_server/sentry_interceptor_spec.rb' - # Offense count: 1 Lint/NonLocalExitFromIterator: Exclude: @@ -147,16 +53,6 @@ Lint/ShadowingOuterLocalVariable: - 'lib/gitlab/git/remote_mirror.rb' - 'lib/gitlab/git/tag.rb' -# Offense count: 5 -# Cop supports --auto-correct. -Lint/UnneededCopDisableDirective: - Exclude: - - 'lib/gitaly_server/exception_sanitizer_interceptor.rb' - - 'lib/gitaly_server/sentry_interceptor.rb' - - 'spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb' - - 'spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb' - - 'spec/lib/gitaly_server/sentry_interceptor_spec.rb' - # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. @@ -165,7 +61,7 @@ Lint/UnusedMethodArgument: - 'lib/gitaly_server/sentry_interceptor.rb' - 'lib/gitlab/git/conflict/parser.rb' -# Offense count: 61 +# Offense count: 62 Metrics/AbcSize: Max: 45 @@ -174,16 +70,16 @@ Metrics/AbcSize: Metrics/BlockLength: Max: 203 -# Offense count: 12 +# Offense count: 11 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 793 + Max: 780 # Offense count: 9 Metrics/CyclomaticComplexity: Max: 12 -# Offense count: 93 +# Offense count: 84 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 44 @@ -224,14 +120,6 @@ Style/Alias: Exclude: - 'lib/gitlab/git/blob.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: percent_q, bare_percent -Style/BarePercentLiterals: - Exclude: - - 'lib/gitlab/git/gitlab_projects.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: Keywords. @@ -246,29 +134,6 @@ Style/Documentation: Enabled: false # Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty, nil, both -Style/EmptyElse: - Exclude: - - 'lib/gitlab/git.rb' - - 'lib/gitlab/git/ref.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Style/ExpandPathArguments: - Exclude: - - 'spec/integration_helper.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - 'lib/gitlab/version_info.rb' - -# Offense count: 3 # Configuration parameters: . # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: @@ -281,20 +146,12 @@ Style/FormatStringToken: Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 8 +# Offense count: 3 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: - - 'lib/gitlab/git/index.rb' - 'lib/gitlab/git/operation_service.rb' - 'lib/gitlab/git/repository.rb' - - 'lib/gitlab/git/tag.rb' - - 'lib/gitlab/git/wiki.rb' - -# Offense count: 42 -# Cop supports --auto-correct. -Style/IfUnlessModifier: - Enabled: false # Offense count: 1 # Cop supports --auto-correct. @@ -325,18 +182,6 @@ Style/NumericLiteralPrefix: Style/NumericLiterals: MinDigits: 6 -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle. -# SupportedStyles: predicate, comparison -Style/NumericPredicate: - Exclude: - - 'spec/**/*' - - 'bin/gitaly-ruby' - - 'lib/gitlab/git/hook.rb' - - 'lib/gitlab/git/repository_mirroring.rb' - - 'lib/gitlab/version_info.rb' - # Offense count: 24 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. @@ -443,7 +288,7 @@ Style/TrivialAccessors: Exclude: - 'lib/gitlab/git/gitlab_projects.rb' -# Offense count: 392 +# Offense count: 412 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: diff --git a/ruby/bin/gitaly-ruby b/ruby/bin/gitaly-ruby index 7abb9442f..9002ad86a 100755 --- a/ruby/bin/gitaly-ruby +++ b/ruby/bin/gitaly-ruby @@ -12,9 +12,7 @@ require_relative '../lib/gitaly_server/rugged_interceptor.rb' SHUTDOWN_TIMEOUT = 600 def main - if ARGV.length != 2 - abort "Usage: #{$0} PPID /path/to/socket" - end + abort "Usage: #{$0} PPID /path/to/socket" if ARGV.length != 2 ppid, socket_path = ARGV ppid_i = ppid.to_i diff --git a/ruby/lib/gitaly_server/client.rb b/ruby/lib/gitaly_server/client.rb index 1f5e4ff62..16e86302f 100644 --- a/ruby/lib/gitaly_server/client.rb +++ b/ruby/lib/gitaly_server/client.rb @@ -20,9 +20,7 @@ module GitalyServer private def server(storage) - unless @servers.has_key?(storage) - raise ServerLookupError.new("cannot find gitaly address for storage #{storage.inspect}") - end + raise ServerLookupError.new("cannot find gitaly address for storage #{storage.inspect}") unless @servers.has_key?(storage) @servers[storage] end diff --git a/ruby/lib/gitaly_server/commit_service.rb b/ruby/lib/gitaly_server/commit_service.rb index 0b943397e..99c41962a 100644 --- a/ruby/lib/gitaly_server/commit_service.rb +++ b/ruby/lib/gitaly_server/commit_service.rb @@ -80,9 +80,7 @@ module GitalyServer repository = nil call.each_remote_read.with_index do |request, index| - if index.zero? - repository = Gitlab::Git::Repository.from_gitaly(request.repository, call) - end + repository = Gitlab::Git::Repository.from_gitaly(request.repository, call) if index.zero? y << Gitaly::FilterShasWithSignaturesResponse.new(shas: Gitlab::Git::Commit.shas_with_signatures(repository, request.shas)) end @@ -96,13 +94,9 @@ module GitalyServer Enumerator.new do |y| each_commit_signature_chunk(repository, request.commit_id) do |signature_chunk, signed_text_chunk| - if signature_chunk.present? - y.yield Gitaly::ExtractCommitSignatureResponse.new(signature: signature_chunk) - end + y.yield Gitaly::ExtractCommitSignatureResponse.new(signature: signature_chunk) if signature_chunk.present? - if signed_text_chunk.present? - y.yield Gitaly::ExtractCommitSignatureResponse.new(signed_text: signed_text_chunk) - end + y.yield Gitaly::ExtractCommitSignatureResponse.new(signed_text: signed_text_chunk) if signed_text_chunk.present? end end end diff --git a/ruby/lib/gitaly_server/exception_sanitizer_interceptor.rb b/ruby/lib/gitaly_server/exception_sanitizer_interceptor.rb index 6ee60f88c..5636cccfb 100644 --- a/ruby/lib/gitaly_server/exception_sanitizer_interceptor.rb +++ b/ruby/lib/gitaly_server/exception_sanitizer_interceptor.rb @@ -6,8 +6,6 @@ module GitalyServer # exceptions from Go then I think we can remove this interceptor. class ExceptionSanitizerInterceptor < GRPC::ServerInterceptor include GitalyServer::Utils - - # rubocop:disable Lint/RescueWithoutErrorClass %i[request_response server_streamer client_streamer bidi_streamer].each do |meth| define_method(meth) do |**, &blk| begin diff --git a/ruby/lib/gitaly_server/operations_service.rb b/ruby/lib/gitaly_server/operations_service.rb index 45a99031e..7b5555cc1 100644 --- a/ruby/lib/gitaly_server/operations_service.rb +++ b/ruby/lib/gitaly_server/operations_service.rb @@ -131,9 +131,7 @@ module GitalyServer y << Gitaly::UserMergeBranchResponse.new(commit_id: commit_id) second_request = session.next - unless second_request.apply - raise GRPC::FailedPrecondition.new('merge aborted by client') - end + raise GRPC::FailedPrecondition.new('merge aborted by client') unless second_request.apply end y << Gitaly::UserMergeBranchResponse.new(branch_update: branch_update_result(result)) @@ -309,9 +307,7 @@ module GitalyServer actions: actions } - if header.start_repository - opts[:start_repository] = Gitlab::Git::GitalyRemoteRepository.new(header.start_repository, call) - end + opts[:start_repository] = Gitlab::Git::GitalyRemoteRepository.new(header.start_repository, call) if header.start_repository optional_fields = { start_branch_name: 'start_branch_name', diff --git a/ruby/lib/gitaly_server/repository_service.rb b/ruby/lib/gitaly_server/repository_service.rb index 9d1d9fe76..4790b600b 100644 --- a/ruby/lib/gitaly_server/repository_service.rb +++ b/ruby/lib/gitaly_server/repository_service.rb @@ -48,9 +48,7 @@ module GitalyServer ssh_key: request.ssh_key.presence, known_hosts: request.known_hosts.presence) - unless success - raise GRPC::Unknown.new("Fetching remote #{request.remote} failed: #{gitlab_projects.output}") - end + raise GRPC::Unknown.new("Fetching remote #{request.remote} failed: #{gitlab_projects.output}") unless success Gitaly::FetchRemoteResponse.new end @@ -113,15 +111,15 @@ module GitalyServer request.entries.each do |entry| key = entry.key value = case entry.value - when :value_str - entry.value_str - when :value_int32 - entry.value_int32 - when :value_bool - entry.value_bool - else - raise GRPC::InvalidArgument, "unknown entry type: #{entry.value}" - end + when :value_str + entry.value_str + when :value_int32 + entry.value_int32 + when :value_bool + entry.value_bool + else + raise GRPC::InvalidArgument, "unknown entry type: #{entry.value}" + end repo.rugged.config[key] = value end diff --git a/ruby/lib/gitaly_server/sentry_interceptor.rb b/ruby/lib/gitaly_server/sentry_interceptor.rb index 8bc1800a2..4453086a3 100644 --- a/ruby/lib/gitaly_server/sentry_interceptor.rb +++ b/ruby/lib/gitaly_server/sentry_interceptor.rb @@ -2,8 +2,6 @@ require 'grpc' require 'raven/base' require_relative 'sentry.rb' - -# rubocop:disable Lint/RescueWithoutErrorClass module GitalyServer class SentryInterceptor < GRPC::ServerInterceptor # Intercept a unary request response call diff --git a/ruby/lib/gitaly_server/utils.rb b/ruby/lib/gitaly_server/utils.rb index cd63749c7..4dddcc7e8 100644 --- a/ruby/lib/gitaly_server/utils.rb +++ b/ruby/lib/gitaly_server/utils.rb @@ -37,7 +37,7 @@ module GitalyServer ) end - def gitaly_tag_from_gitlab_tag(gitlab_tag, commit=nil) + def gitaly_tag_from_gitlab_tag(gitlab_tag, commit = nil) tag_message = gitlab_tag.message.to_s tag = Gitaly::Tag.new( name: gitlab_tag.name.b, diff --git a/ruby/lib/gitlab/git.rb b/ruby/lib/gitlab/git.rb index bf3ea44ec..24ef40cfd 100644 --- a/ruby/lib/gitlab/git.rb +++ b/ruby/lib/gitlab/git.rb @@ -71,11 +71,7 @@ module Gitlab def branch_name(ref) ref = ref.to_s - if self.branch_ref?(ref) - self.ref_name(ref) - else - nil - end + self.ref_name(ref) if self.branch_ref?(ref) end def committer_hash(email:, name:) @@ -90,11 +86,7 @@ module Gitlab def tag_name(ref) ref = ref.to_s - if self.tag_ref?(ref) - self.ref_name(ref) - else - nil - end + self.ref_name(ref) if self.tag_ref?(ref) end def tag_ref?(ref) @@ -116,9 +108,7 @@ module Gitlab def check_namespace!(*objects) expected_namespace = self.name + '::' objects.each do |object| - unless object.class.name.start_with?(expected_namespace) - raise ArgumentError, "expected object in #{expected_namespace}, got #{object}" - end + raise ArgumentError, "expected object in #{expected_namespace}, got #{object}" unless object.class.name.start_with?(expected_namespace) end end diff --git a/ruby/lib/gitlab/git/blob.rb b/ruby/lib/gitlab/git/blob.rb index 58d300fa0..9152d79ff 100644 --- a/ruby/lib/gitlab/git/blob.rb +++ b/ruby/lib/gitlab/git/blob.rb @@ -16,7 +16,8 @@ module Gitlab LFS_POINTER_MIN_SIZE = 120.bytes LFS_POINTER_MAX_SIZE = 200.bytes - attr_accessor :name, :path, :size, :data, :mode, :id, :commit_id, :loaded_size, :binary + attr_accessor :size, :mode, :id, :commit_id, :loaded_size, :binary + attr_writer :data, :name, :path class << self def find(repository, sha, path, limit: MAX_DATA_DISPLAY_SIZE) diff --git a/ruby/lib/gitlab/git/conflict/file.rb b/ruby/lib/gitlab/git/conflict/file.rb index f08dab59c..6f7874582 100644 --- a/ruby/lib/gitlab/git/conflict/file.rb +++ b/ruby/lib/gitlab/git/conflict/file.rb @@ -86,9 +86,7 @@ module Gitlab end def resolve_content(resolution) - if resolution == content - raise Gitlab::Git::Conflict::Resolver::ResolutionError, "Resolved content has no changes for file #{our_path}" - end + raise Gitlab::Git::Conflict::Resolver::ResolutionError, "Resolved content has no changes for file #{our_path}" if resolution == content resolution end diff --git a/ruby/lib/gitlab/git/conflict/resolver.rb b/ruby/lib/gitlab/git/conflict/resolver.rb index 86a16f0f2..a2621ac93 100644 --- a/ruby/lib/gitlab/git/conflict/resolver.rb +++ b/ruby/lib/gitlab/git/conflict/resolver.rb @@ -31,9 +31,7 @@ module Gitlab def conflict_files(repository, index) index.conflicts.map do |conflict| - unless conflict[:theirs] && conflict[:ours] - raise ListError, 'conflict side missing' - end + raise ListError, 'conflict side missing' unless conflict[:theirs] && conflict[:ours] Gitlab::Git::Conflict::File.new( repository, diff --git a/ruby/lib/gitlab/git/gitlab_projects.rb b/ruby/lib/gitlab/git/gitlab_projects.rb index 14ea2c61c..5cbe85574 100644 --- a/ruby/lib/gitlab/git/gitlab_projects.rb +++ b/ruby/lib/gitlab/git/gitlab_projects.rb @@ -6,10 +6,6 @@ module Gitlab include Gitlab::Git::Popen include Gitlab::Utils::StrongMemoize - # Name of shard where repositories are stored. - # Example: nfs-file06 - attr_reader :shard_name - # Relative path is a directory name for repository with .git at the end. # Example: gitlab-org/gitlab-test.git attr_reader :repository_relative_path @@ -41,7 +37,6 @@ module Gitlab @output = StringIO.new end - def shard_name raise "don't use shard_name in gitaly-ruby" end @@ -72,9 +67,7 @@ module Gitlab setup_ssh_auth(ssh_key, known_hosts) do |env| run_with_timeout(cmd, timeout, repository_absolute_path, env).tap do |success| - unless success - logger.error "Fetching remote #{name} for repository #{repository_absolute_path} failed." - end + logger.error "Fetching remote #{name} for repository #{repository_absolute_path} failed." unless success end end end @@ -87,9 +80,7 @@ module Gitlab success = run_with_timeout(cmd, timeout, repository_absolute_path) - unless success - logger.error("Pushing branches to remote #{remote_name} failed.") - end + logger.error("Pushing branches to remote #{remote_name} failed.") unless success success end @@ -102,9 +93,7 @@ module Gitlab success = run(cmd, repository_absolute_path) - unless success - logger.error("Pushing deleted branches to remote #{remote_name} failed.") - end + logger.error("Pushing deleted branches to remote #{remote_name} failed.") unless success success end @@ -150,7 +139,7 @@ module Gitlab # paths with spaces in them. We trust the user not to embed single or double # quotes in the key or value. def custom_ssh_script(options = {}) - args = options.map { |k, v| %Q{'-o#{k}="#{v}"'} }.join(' ') + args = options.map { |k, v| %{'-o#{k}="#{v}"'} }.join(' ') [ "#!/bin/sh", @@ -211,4 +200,3 @@ module Gitlab end end end - diff --git a/ruby/lib/gitlab/git/hooks_service.rb b/ruby/lib/gitlab/git/hooks_service.rb index e67cacdb9..d6a08a79c 100644 --- a/ruby/lib/gitlab/git/hooks_service.rb +++ b/ruby/lib/gitlab/git/hooks_service.rb @@ -14,9 +14,7 @@ module Gitlab %w(pre-receive update).each do |hook_name| status, message = run_hook(hook_name) - unless status - raise PreReceiveError, message - end + raise PreReceiveError, message unless status end yield(self).tap do diff --git a/ruby/lib/gitlab/git/index.rb b/ruby/lib/gitlab/git/index.rb index af6786eb3..f6bf1dfe0 100644 --- a/ruby/lib/gitlab/git/index.rb +++ b/ruby/lib/gitlab/git/index.rb @@ -34,9 +34,7 @@ module Gitlab def create(options) options = normalize_options(options) - if get(options[:file_path]) - raise IndexError, "A file with this name already exists" - end + raise IndexError, "A file with this name already exists" if get(options[:file_path]) add_blob(options) end @@ -44,13 +42,9 @@ module Gitlab def create_dir(options) options = normalize_options(options) - if get(options[:file_path]) - raise IndexError, "A file with this name already exists" - end + raise IndexError, "A file with this name already exists" if get(options[:file_path]) - if dir_exists?(options[:file_path]) - raise IndexError, "A directory with this name already exists" - end + raise IndexError, "A directory with this name already exists" if dir_exists?(options[:file_path]) options = options.dup options[:file_path] += '/.gitkeep' @@ -63,9 +57,7 @@ module Gitlab options = normalize_options(options) file_entry = get(options[:file_path]) - unless file_entry - raise IndexError, "A file with this name doesn't exist" - end + raise IndexError, "A file with this name doesn't exist" unless file_entry add_blob(options, mode: file_entry[:mode]) end @@ -74,13 +66,9 @@ module Gitlab options = normalize_options(options) file_entry = get(options[:previous_path]) - unless file_entry - raise IndexError, "A file with this name doesn't exist" - end + raise IndexError, "A file with this name doesn't exist" unless file_entry - if get(options[:file_path]) - raise IndexError, "A file with this name already exists" - end + raise IndexError, "A file with this name already exists" if get(options[:file_path]) raw_index.remove(options[:previous_path]) @@ -90,9 +78,7 @@ module Gitlab def delete(options) options = normalize_options(options) - unless get(options[:file_path]) - raise IndexError, "A file with this name doesn't exist" - end + raise IndexError, "A file with this name doesn't exist" unless get(options[:file_path]) raw_index.remove(options[:file_path]) end @@ -101,9 +87,7 @@ module Gitlab options = normalize_options(options) file_entry = get(options[:file_path]) - unless file_entry - raise IndexError, "A file with this name doesn't exist" - end + raise IndexError, "A file with this name doesn't exist" unless file_entry mode = options[:execute_filemode] ? EXECUTE_MODE : DEFAULT_MODE @@ -120,16 +104,12 @@ module Gitlab end def normalize_path(path) - unless path - raise IndexError, "You must provide a file path" - end + raise IndexError, "You must provide a file path" unless path pathname = Gitlab::Git::PathHelper.normalize_path(path.dup) pathname.each_filename do |segment| - if segment == '..' - raise IndexError, 'Path cannot include directory traversal' - end + raise IndexError, 'Path cannot include directory traversal' if segment == '..' end pathname.to_s @@ -137,9 +117,7 @@ module Gitlab def add_blob(options, mode: nil) content = options[:content] - unless content - raise IndexError, "You must provide content" - end + raise IndexError, "You must provide content" unless content content = Base64.decode64(content) if options[:encoding] == 'base64' @@ -158,9 +136,7 @@ module Gitlab end def validate_action!(action) - unless ACTIONS.include?(action.to_s) - raise ArgumentError, "Unknown action '#{action}'" - end + raise ArgumentError, "Unknown action '#{action}'" unless ACTIONS.include?(action.to_s) end end end diff --git a/ruby/lib/gitlab/git/lfs_changes.rb b/ruby/lib/gitlab/git/lfs_changes.rb index 964e0f194..d3a44c07b 100644 --- a/ruby/lib/gitlab/git/lfs_changes.rb +++ b/ruby/lib/gitlab/git/lfs_changes.rb @@ -26,9 +26,7 @@ module Gitlab def git_all_pointers params = {} - if rev_list_supports_new_options? - params[:options] = ["--filter=blob:limit=#{Gitlab::Git::Blob::LFS_POINTER_MAX_SIZE}"] - end + params[:options] = ["--filter=blob:limit=#{Gitlab::Git::Blob::LFS_POINTER_MAX_SIZE}"] if rev_list_supports_new_options? rev_list.all_objects(rev_list_params(params)) do |object_ids| Gitlab::Git::Blob.batch_lfs_pointers(@repository, object_ids) diff --git a/ruby/lib/gitlab/git/operation_service.rb b/ruby/lib/gitlab/git/operation_service.rb index a660edcee..52a6b617d 100644 --- a/ruby/lib/gitlab/git/operation_service.rb +++ b/ruby/lib/gitlab/git/operation_service.rb @@ -117,9 +117,7 @@ module Gitlab # Make commit newrev = yield - unless newrev - raise Gitlab::Git::CommitError.new('Failed to create commit') - end + raise Gitlab::Git::CommitError.new('Failed to create commit') unless newrev branch = repository.find_branch(branch_name) oldrev = find_oldrev_from_branch(newrev, branch) @@ -188,9 +186,7 @@ module Gitlab end def update_autocrlf_option - if repository.autocrlf != :input - repository.autocrlf = :input - end + repository.autocrlf = :input if repository.autocrlf != :input end end end diff --git a/ruby/lib/gitlab/git/popen.rb b/ruby/lib/gitlab/git/popen.rb index 53996b682..cd86e52e1 100644 --- a/ruby/lib/gitlab/git/popen.rb +++ b/ruby/lib/gitlab/git/popen.rb @@ -6,9 +6,7 @@ module Gitlab FAST_GIT_PROCESS_TIMEOUT = 15.seconds def popen(cmd, path, vars = {}, lazy_block: nil) - unless cmd.is_a?(Array) - raise "System commands must be given as an array of strings" - end + raise "System commands must be given as an array of strings" unless cmd.is_a?(Array) path ||= Dir.pwd vars['PWD'] = path @@ -43,16 +41,12 @@ module Gitlab end def popen_with_timeout(cmd, timeout, path, vars = {}) - unless cmd.is_a?(Array) - raise "System commands must be given as an array of strings" - end + raise "System commands must be given as an array of strings" unless cmd.is_a?(Array) path ||= Dir.pwd vars['PWD'] = path - unless File.directory?(path) - FileUtils.mkdir_p(path) - end + FileUtils.mkdir_p(path) unless File.directory?(path) rout, wout = IO.pipe rerr, werr = IO.pipe diff --git a/ruby/lib/gitlab/git/ref.rb b/ruby/lib/gitlab/git/ref.rb index 79dea23f6..fdf35e473 100644 --- a/ruby/lib/gitlab/git/ref.rb +++ b/ruby/lib/gitlab/git/ref.rb @@ -42,8 +42,6 @@ module Gitlab target.name elsif target.is_a? String target - else - nil end end end diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index 06601017a..383c2a1ac 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -101,9 +101,6 @@ module Gitlab # Directory name of repo attr_reader :name - # Relative path of repo - attr_reader :relative_path - attr_reader :gitlab_projects, :storage, :gl_repository, :relative_path def initialize(gitaly_repository, path, gl_repository, gitlab_projects, combined_alt_dirs = "") @@ -222,9 +219,7 @@ module Gitlab if ref.target.is_a?(Rugged::Tag::Annotation) tag_message = ref.target.message - if tag_message.respond_to?(:chomp) - message = tag_message.chomp - end + message = tag_message.chomp if tag_message.respond_to?(:chomp) end target_commit = Gitlab::Git::Commit.find(self, ref.target) @@ -452,7 +447,7 @@ module Gitlab end def diff_exists?(sha1, sha2) - !rugged.diff(sha1, sha2).empty? + rugged.diff(sha1, sha2).size.positive? end def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:) @@ -603,9 +598,7 @@ module Gitlab def with_repo_tmp_commit(start_repository, start_branch_name, sha) source_ref = start_branch_name - unless Gitlab::Git.branch_ref?(source_ref) - source_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{source_ref}" - end + source_ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{source_ref}" unless Gitlab::Git.branch_ref?(source_ref) tmp_ref = fetch_ref( start_repository, @@ -745,9 +738,7 @@ module Gitlab # the case of mirrors we map its refs (that would usualy go under # [remote_name]/) to the top level namespace. We clean the mapping so # those don't get deleted. - if rugged.config["remote.#{remote_name}.mirror"] - rugged.config.delete("remote.#{remote_name}.fetch") - end + rugged.config.delete("remote.#{remote_name}.fetch") if rugged.config["remote.#{remote_name}.mirror"] rugged.remotes.delete(remote_name) true @@ -812,9 +803,7 @@ module Gitlab args.push('--objects') if objects - if options.any? - args.push(*options) - end + args.push(*options) if options.any? run_git!(args, lazy_block: block) end @@ -832,9 +821,7 @@ module Gitlab cmd.unshift("nice") if nice object_directories = alternate_object_directories - if object_directories.any? - env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = object_directories.join(File::PATH_SEPARATOR) - end + env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = object_directories.join(File::PATH_SEPARATOR) if object_directories.any? popen(cmd, chdir, env, lazy_block: lazy_block, &block) end @@ -958,9 +945,7 @@ module Gitlab stdin.write(instructions.join) end - unless status.zero? - raise GitError, "Could not delete refs #{ref_names}: #{message}" - end + raise GitError, "Could not delete refs #{ref_names}: #{message}" unless status.zero? end def rugged_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:) diff --git a/ruby/lib/gitlab/git/tag.rb b/ruby/lib/gitlab/git/tag.rb index 013bea479..818c1077e 100644 --- a/ruby/lib/gitlab/git/tag.rb +++ b/ruby/lib/gitlab/git/tag.rb @@ -61,9 +61,7 @@ module Gitlab @target = @raw_tag.id @message = message_from_gitaly_tag - if @raw_tag.target_commit.present? - @target_commit = Gitlab::Git::Commit.decorate(repository, @raw_tag.target_commit) - end + @target_commit = Gitlab::Git::Commit.decorate(repository, @raw_tag.target_commit) if @raw_tag.target_commit.present? end def message diff --git a/ruby/lib/gitlab/git/wiki.rb b/ruby/lib/gitlab/git/wiki.rb index 2e7be2c45..25f47b306 100644 --- a/ruby/lib/gitlab/git/wiki.rb +++ b/ruby/lib/gitlab/git/wiki.rb @@ -104,9 +104,7 @@ module Gitlab end def assert_type!(object, klass) - unless object.is_a?(klass) - raise ArgumentError, "expected a #{klass}, got #{object.inspect}" - end + raise ArgumentError, "expected a #{klass}, got #{object.inspect}" unless object.is_a?(klass) end def committer_with_hooks(commit_details) @@ -183,9 +181,7 @@ module Gitlab end def gollum_find_page(title:, version: nil, dir: nil) - if version - version = Gitlab::Git::Commit.find(@repository, version).id - end + version = Gitlab::Git::Commit.find(@repository, version).id if version gollum_page = gollum_wiki.page(title, version, dir) return unless gollum_page diff --git a/ruby/lib/gitlab/git/wiki_page.rb b/ruby/lib/gitlab/git/wiki_page.rb index 35010c616..3fbdf0ffe 100644 --- a/ruby/lib/gitlab/git/wiki_page.rb +++ b/ruby/lib/gitlab/git/wiki_page.rb @@ -1,7 +1,7 @@ module Gitlab module Git class WikiPage - attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :text_data, :historical + attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :historical def initialize(gollum_page, version) @gollum_page = gollum_page @@ -18,7 +18,7 @@ module Gitlab end def formatted_data - @gollum_page.formatted_data + @gollum_page.formatted_data end def historical? diff --git a/ruby/lib/gitlab/gollum.rb b/ruby/lib/gitlab/gollum.rb index 2eb5d78aa..4bf08411f 100644 --- a/ruby/lib/gitlab/gollum.rb +++ b/ruby/lib/gitlab/gollum.rb @@ -7,7 +7,7 @@ Gollum::Page.per_page = 20 # Magic number from Kaminari.config.default_per_page module Gollum class Page - def text_data(encoding=nil) + def text_data(encoding = nil) data = if raw_data.respond_to?(:encoding) raw_data.force_encoding(encoding || Encoding::UTF_8) else diff --git a/ruby/lib/gitlab/version_info.rb b/ruby/lib/gitlab/version_info.rb index 6ee41e85c..b5f4bec54 100644 --- a/ruby/lib/gitlab/version_info.rb +++ b/ruby/lib/gitlab/version_info.rb @@ -41,7 +41,7 @@ module Gitlab def to_s if valid? - "%d.%d.%d" % [@major, @minor, @patch] + format("%d.%d.%d", @major, @minor, @patch) else "Unknown" end diff --git a/ruby/spec/integration_helper.rb b/ruby/spec/integration_helper.rb index 6678b12e7..a8c4e586e 100644 --- a/ruby/spec/integration_helper.rb +++ b/ruby/spec/integration_helper.rb @@ -4,8 +4,8 @@ require 'gitaly' require 'spec_helper' SOCKET_PATH = 'gitaly.socket'.freeze -GITALY_RUBY_DIR = File.expand_path('../..', __FILE__) -TMP_DIR = File.expand_path('../../tmp', __FILE__) +GITALY_RUBY_DIR = File.expand_path('..', __dir__) +TMP_DIR = File.expand_path('../tmp', __dir__) module IntegrationClient def gitaly_stub(service) @@ -19,7 +19,7 @@ module IntegrationClient end def start_gitaly - build_dir = File.expand_path('../../../_build', __FILE__) + build_dir = File.expand_path('../../_build', __dir__) gitlab_shell_dir = File.join(TMP_DIR, 'gitlab-shell') FileUtils.mkdir_p([TMP_DIR, File.join(gitlab_shell_dir, 'hooks')]) @@ -27,10 +27,10 @@ def start_gitaly config_toml = <<~CONFIG socket_path = "#{SOCKET_PATH}" bin_dir = "#{build_dir}/bin" - + [gitlab-shell] dir = "#{gitlab_shell_dir}" - + [gitaly-ruby] dir = "#{GITALY_RUBY_DIR}" diff --git a/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb b/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb index 48b48a8d9..06fabffc8 100644 --- a/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb +++ b/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' require_relative '../../../lib/gitaly_server/exception_sanitizer_interceptor.rb' - -# rubocop:disable Lint/RescueWithoutErrorClass describe GitalyServer::ExceptionSanitizerInterceptor do let(:meth) { GitalyServer::RefService.instance_method(:create_branch) } let(:ex) { StandardError.new("error: failed to push some refs to 'https://fO0BA7:HunTer!@github.com/ruby/ruby.git'") } diff --git a/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb b/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb index 61533fac8..01aab9f94 100644 --- a/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb +++ b/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb @@ -9,7 +9,7 @@ describe GitalyServer::RuggedInterceptor do let(:call) { double(metadata: {}) } subject do - described_class.new.server_streamer(call: call, method: meth) { } + described_class.new.server_streamer(call: call, method: meth) {} end context 'no Rugged repositories initialized' do diff --git a/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb b/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb index 2363bba9d..c582e7362 100644 --- a/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb +++ b/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' require 'raven/base' require 'raven/transports/dummy' require_relative '../../../../lib/gitaly_server/sentry.rb' - -# rubocop:disable Lint/RescueWithoutErrorClass describe GitalyServer::Sentry::URLSanitizer do let(:meth) { GitalyServer::RefService.instance_method(:create_branch) } let(:ex) { StandardError.new("error: failed to push some refs to 'https://fO0BA7:HunTer!@github.com/ruby/ruby.git'") } diff --git a/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb b/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb index 7c1c86034..4fcd0dbfb 100644 --- a/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb +++ b/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' require_relative '../../../lib/gitaly_server/sentry_interceptor.rb' - -# rubocop:disable Lint/RescueWithoutErrorClass describe GitalyServer::SentryInterceptor do describe 'handling exceptions' do let(:meth) { GitalyServer::RefService.instance_method(:create_branch) } diff --git a/ruby/spec/lib/gitlab/version_info_spec.rb b/ruby/spec/lib/gitlab/version_info_spec.rb index 923b4a7db..8cf95ba33 100644 --- a/ruby/spec/lib/gitlab/version_info_spec.rb +++ b/ruby/spec/lib/gitlab/version_info_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' describe Gitlab::VersionInfo do let(:unknown) { described_class.new } - let(:v0_0_1) { described_class.new(0, 0, 1)} + let(:v0_0_1) { described_class.new(0, 0, 1) } let(:v0_1_0) { described_class.new(0, 1, 0) } let(:v1_0_0) { described_class.new(1, 0, 0) } let(:v1_0_1) { described_class.new(1, 0, 1) } let(:v1_1_0) { described_class.new(1, 1, 0) } - let(:v2_0_0) { described_class.new(2, 0, 0) } + let(:v2_0_0) { described_class.new(2, 0, 0) } context '>' do it { expect(v2_0_0).to be > v1_1_0 } @@ -48,8 +48,8 @@ describe Gitlab::VersionInfo do context 'unknown' do it { expect(unknown).not_to be v0_0_1 } it { expect(unknown).not_to be described_class.new } - it { expect {unknown > v0_0_1}.to raise_error(ArgumentError) } - it { expect {unknown < v0_0_1}.to raise_error(ArgumentError) } + it { expect { unknown > v0_0_1 }.to raise_error(ArgumentError) } + it { expect { unknown < v0_0_1 }.to raise_error(ArgumentError) } end context 'parse' do diff --git a/ruby/spec/test_repo_helper.rb b/ruby/spec/test_repo_helper.rb index 4e773211c..a9ecb7dc5 100644 --- a/ruby/spec/test_repo_helper.rb +++ b/ruby/spec/test_repo_helper.rb @@ -40,6 +40,7 @@ module TestRepo def repo_path_from_gitaly(gitaly_repo) storage_name = gitaly_repo.storage_name raise "this helper does not know storage #{storage_name.inspect}" unless storage_name == DEFAULT_STORAGE_NAME + File.join(DEFAULT_STORAGE_DIR, gitaly_repo.relative_path) end |