diff --git a/changelogs/unreleased/enable-frozen-string-lib-gitlab.yml b/changelogs/unreleased/enable-frozen-string-lib-gitlab.yml new file mode 100644 index 00000000000..4a216c46d38 --- /dev/null +++ b/changelogs/unreleased/enable-frozen-string-lib-gitlab.yml @@ -0,0 +1,5 @@ +--- +title: Enable some frozen string in lib/gitlab +merge_request: +author: gfyoung +type: performance diff --git a/lib/gitlab/auth/activity.rb b/lib/gitlab/auth/activity.rb index 761f0819c60..558628b5422 100644 --- a/lib/gitlab/auth/activity.rb +++ b/lib/gitlab/auth/activity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth ## diff --git a/lib/gitlab/auth/database/authentication.rb b/lib/gitlab/auth/database/authentication.rb index 1234ace0334..c0dc2b0875f 100644 --- a/lib/gitlab/auth/database/authentication.rb +++ b/lib/gitlab/auth/database/authentication.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # These calls help to authenticate to OAuth provider by providing username and password # diff --git a/lib/gitlab/auth/ip_rate_limiter.rb b/lib/gitlab/auth/ip_rate_limiter.rb index e6173d45af3..81e616fa20a 100644 --- a/lib/gitlab/auth/ip_rate_limiter.rb +++ b/lib/gitlab/auth/ip_rate_limiter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth class IpRateLimiter diff --git a/lib/gitlab/auth/ldap/access.rb b/lib/gitlab/auth/ldap/access.rb index f323d2e0f7a..c875bba4bcb 100644 --- a/lib/gitlab/auth/ldap/access.rb +++ b/lib/gitlab/auth/ldap/access.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # LDAP authorization model # # * Check if we are allowed access (not blocked) diff --git a/lib/gitlab/auth/ldap/adapter.rb b/lib/gitlab/auth/ldap/adapter.rb index 82ff1e77e5c..42c657afe6a 100644 --- a/lib/gitlab/auth/ldap/adapter.rb +++ b/lib/gitlab/auth/ldap/adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module LDAP diff --git a/lib/gitlab/auth/ldap/auth_hash.rb b/lib/gitlab/auth/ldap/auth_hash.rb index ac5c14d374d..83fdc8a8c76 100644 --- a/lib/gitlab/auth/ldap/auth_hash.rb +++ b/lib/gitlab/auth/ldap/auth_hash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Class to parse and transform the info provided by omniauth # module Gitlab diff --git a/lib/gitlab/auth/ldap/authentication.rb b/lib/gitlab/auth/ldap/authentication.rb index 7c134fb6438..174e81dd603 100644 --- a/lib/gitlab/auth/ldap/authentication.rb +++ b/lib/gitlab/auth/ldap/authentication.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # These calls help to authenticate to LDAP by providing username and password # # Since multiple LDAP servers are supported, it will loop through all of them diff --git a/lib/gitlab/auth/ldap/config.rb b/lib/gitlab/auth/ldap/config.rb index d4415eaa6dc..7ceb96f502b 100644 --- a/lib/gitlab/auth/ldap/config.rb +++ b/lib/gitlab/auth/ldap/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load a specific server configuration module Gitlab module Auth diff --git a/lib/gitlab/auth/ldap/dn.rb b/lib/gitlab/auth/ldap/dn.rb index 1fa5338f5a6..5df914aa367 100644 --- a/lib/gitlab/auth/ldap/dn.rb +++ b/lib/gitlab/auth/ldap/dn.rb @@ -1,4 +1,5 @@ # -*- ruby encoding: utf-8 -*- +# frozen_string_literal: true # Based on the `ruby-net-ldap` gem's `Net::LDAP::DN` # diff --git a/lib/gitlab/auth/ldap/ldap_connection_error.rb b/lib/gitlab/auth/ldap/ldap_connection_error.rb index ef0a695742b..d0e5f24d203 100644 --- a/lib/gitlab/auth/ldap/ldap_connection_error.rb +++ b/lib/gitlab/auth/ldap/ldap_connection_error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module LDAP diff --git a/lib/gitlab/auth/ldap/person.rb b/lib/gitlab/auth/ldap/person.rb index 8dfae3ee541..a0244a3cea1 100644 --- a/lib/gitlab/auth/ldap/person.rb +++ b/lib/gitlab/auth/ldap/person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module LDAP diff --git a/lib/gitlab/auth/ldap/user.rb b/lib/gitlab/auth/ldap/user.rb index 3c21ddf3241..9c71671f409 100644 --- a/lib/gitlab/auth/ldap/user.rb +++ b/lib/gitlab/auth/ldap/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # LDAP extension for User model # # * Find or create user from omniauth.auth data diff --git a/lib/gitlab/auth/o_auth/auth_hash.rb b/lib/gitlab/auth/o_auth/auth_hash.rb index ed8fba94305..4a5f9d2839d 100644 --- a/lib/gitlab/auth/o_auth/auth_hash.rb +++ b/lib/gitlab/auth/o_auth/auth_hash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Class to parse and transform the info provided by omniauth # module Gitlab diff --git a/lib/gitlab/auth/o_auth/authentication.rb b/lib/gitlab/auth/o_auth/authentication.rb index d4e7f35c857..5f008678bd1 100644 --- a/lib/gitlab/auth/o_auth/authentication.rb +++ b/lib/gitlab/auth/o_auth/authentication.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # These calls help to authenticate to OAuth provider by providing username and password # diff --git a/lib/gitlab/auth/o_auth/identity_linker.rb b/lib/gitlab/auth/o_auth/identity_linker.rb index de92d7a214d..e69c2bb54dc 100644 --- a/lib/gitlab/auth/o_auth/identity_linker.rb +++ b/lib/gitlab/auth/o_auth/identity_linker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module OAuth diff --git a/lib/gitlab/auth/o_auth/provider.rb b/lib/gitlab/auth/o_auth/provider.rb index 26da9d09ccc..9fdf3324db3 100644 --- a/lib/gitlab/auth/o_auth/provider.rb +++ b/lib/gitlab/auth/o_auth/provider.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module OAuth diff --git a/lib/gitlab/auth/o_auth/session.rb b/lib/gitlab/auth/o_auth/session.rb index 8f2b4d58552..4925b107042 100644 --- a/lib/gitlab/auth/o_auth/session.rb +++ b/lib/gitlab/auth/o_auth/session.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # :nocov: module Gitlab module Auth diff --git a/lib/gitlab/auth/o_auth/user.rb b/lib/gitlab/auth/o_auth/user.rb index 2b4f6ed75e5..a4e8a41b246 100644 --- a/lib/gitlab/auth/o_auth/user.rb +++ b/lib/gitlab/auth/o_auth/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # OAuth extension for User model # # * Find GitLab user based on omniauth uid and provider diff --git a/lib/gitlab/auth/omniauth_identity_linker_base.rb b/lib/gitlab/auth/omniauth_identity_linker_base.rb index 8ae29a02a13..253445570f2 100644 --- a/lib/gitlab/auth/omniauth_identity_linker_base.rb +++ b/lib/gitlab/auth/omniauth_identity_linker_base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth class OmniauthIdentityLinkerBase diff --git a/lib/gitlab/auth/request_authenticator.rb b/lib/gitlab/auth/request_authenticator.rb index 66de52506ce..cb9f2582936 100644 --- a/lib/gitlab/auth/request_authenticator.rb +++ b/lib/gitlab/auth/request_authenticator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Use for authentication only, in particular for Rack::Attack. # Does not perform authorization of scopes, etc. module Gitlab diff --git a/lib/gitlab/auth/result.rb b/lib/gitlab/auth/result.rb index 00cdc94a9ef..78fa25c5516 100644 --- a/lib/gitlab/auth/result.rb +++ b/lib/gitlab/auth/result.rb @@ -1,4 +1,7 @@ -module Gitlab # rubocop:disable Naming/FileName +# rubocop:disable Naming/FileName +# frozen_string_literal: true + +module Gitlab module Auth Result = Struct.new(:actor, :project, :type, :authentication_abilities) do def ci?(for_project) diff --git a/lib/gitlab/auth/saml/auth_hash.rb b/lib/gitlab/auth/saml/auth_hash.rb index 3bc5e2864df..316354fd50c 100644 --- a/lib/gitlab/auth/saml/auth_hash.rb +++ b/lib/gitlab/auth/saml/auth_hash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module Saml diff --git a/lib/gitlab/auth/saml/config.rb b/lib/gitlab/auth/saml/config.rb index 625dab7c6f4..8cb999f50d4 100644 --- a/lib/gitlab/auth/saml/config.rb +++ b/lib/gitlab/auth/saml/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module Saml diff --git a/lib/gitlab/auth/saml/identity_linker.rb b/lib/gitlab/auth/saml/identity_linker.rb index 7e4b191d512..ae0d6dded4e 100644 --- a/lib/gitlab/auth/saml/identity_linker.rb +++ b/lib/gitlab/auth/saml/identity_linker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth module Saml diff --git a/lib/gitlab/auth/saml/user.rb b/lib/gitlab/auth/saml/user.rb index 6c3b75f3eb0..ec95bc46791 100644 --- a/lib/gitlab/auth/saml/user.rb +++ b/lib/gitlab/auth/saml/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # SAML extension for User model # # * Find GitLab user based on SAML uid and provider diff --git a/lib/gitlab/auth/too_many_ips.rb b/lib/gitlab/auth/too_many_ips.rb index ed862791551..ee4d80e6b89 100644 --- a/lib/gitlab/auth/too_many_ips.rb +++ b/lib/gitlab/auth/too_many_ips.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth class TooManyIps < StandardError diff --git a/lib/gitlab/auth/unique_ips_limiter.rb b/lib/gitlab/auth/unique_ips_limiter.rb index baa1f802d8a..31dd61ae6cf 100644 --- a/lib/gitlab/auth/unique_ips_limiter.rb +++ b/lib/gitlab/auth/unique_ips_limiter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth class UniqueIpsLimiter diff --git a/lib/gitlab/auth/user_access_denied_reason.rb b/lib/gitlab/auth/user_access_denied_reason.rb index 1893cb001b2..fd09fe76c02 100644 --- a/lib/gitlab/auth/user_access_denied_reason.rb +++ b/lib/gitlab/auth/user_access_denied_reason.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth class UserAccessDeniedReason diff --git a/lib/gitlab/auth/user_auth_finders.rb b/lib/gitlab/auth/user_auth_finders.rb index 064cba43278..5df6db6f366 100644 --- a/lib/gitlab/auth/user_auth_finders.rb +++ b/lib/gitlab/auth/user_auth_finders.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Auth AuthenticationError = Class.new(StandardError) diff --git a/lib/gitlab/badge/base.rb b/lib/gitlab/badge/base.rb index 909fa24fa90..fb55b9e2f1f 100644 --- a/lib/gitlab/badge/base.rb +++ b/lib/gitlab/badge/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge class Base diff --git a/lib/gitlab/badge/coverage/metadata.rb b/lib/gitlab/badge/coverage/metadata.rb index e898f5d790e..9181ba2d4b0 100644 --- a/lib/gitlab/badge/coverage/metadata.rb +++ b/lib/gitlab/badge/coverage/metadata.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge module Coverage diff --git a/lib/gitlab/badge/coverage/report.rb b/lib/gitlab/badge/coverage/report.rb index 16fd6f01495..a7fcb6b0fca 100644 --- a/lib/gitlab/badge/coverage/report.rb +++ b/lib/gitlab/badge/coverage/report.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge module Coverage diff --git a/lib/gitlab/badge/coverage/template.rb b/lib/gitlab/badge/coverage/template.rb index afbf9dd17e3..817dc28f84a 100644 --- a/lib/gitlab/badge/coverage/template.rb +++ b/lib/gitlab/badge/coverage/template.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge module Coverage diff --git a/lib/gitlab/badge/metadata.rb b/lib/gitlab/badge/metadata.rb index 8ad6f3cb986..b9ae68134b0 100644 --- a/lib/gitlab/badge/metadata.rb +++ b/lib/gitlab/badge/metadata.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge ## diff --git a/lib/gitlab/badge/pipeline/metadata.rb b/lib/gitlab/badge/pipeline/metadata.rb index db1e9f8cfb8..d4d789558c9 100644 --- a/lib/gitlab/badge/pipeline/metadata.rb +++ b/lib/gitlab/badge/pipeline/metadata.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge module Pipeline diff --git a/lib/gitlab/badge/pipeline/status.rb b/lib/gitlab/badge/pipeline/status.rb index d1d9b7949f5..37e61f07e5b 100644 --- a/lib/gitlab/badge/pipeline/status.rb +++ b/lib/gitlab/badge/pipeline/status.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge module Pipeline diff --git a/lib/gitlab/badge/pipeline/template.rb b/lib/gitlab/badge/pipeline/template.rb index e09db32262d..64c3dfcd10b 100644 --- a/lib/gitlab/badge/pipeline/template.rb +++ b/lib/gitlab/badge/pipeline/template.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge module Pipeline diff --git a/lib/gitlab/badge/template.rb b/lib/gitlab/badge/template.rb index bfeb0052642..ed2ec50b197 100644 --- a/lib/gitlab/badge/template.rb +++ b/lib/gitlab/badge/template.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Badge ## diff --git a/lib/gitlab/bare_repository_import/importer.rb b/lib/gitlab/bare_repository_import/importer.rb index 04aa6aab771..3cd327f5109 100644 --- a/lib/gitlab/bare_repository_import/importer.rb +++ b/lib/gitlab/bare_repository_import/importer.rb @@ -1,10 +1,15 @@ +# frozen_string_literal: true + module Gitlab module BareRepositoryImport class Importer NoAdminError = Class.new(StandardError) def self.execute(import_path) - import_path << '/' unless import_path.ends_with?('/') + unless import_path.ends_with?('/') + import_path = "#{import_path}/" + end + repos_to_import = Dir.glob(import_path + '**/*.git') unless user = User.admins.order_id_asc.first diff --git a/lib/gitlab/bare_repository_import/repository.rb b/lib/gitlab/bare_repository_import/repository.rb index c0c666dfb7b..b903c581aac 100644 --- a/lib/gitlab/bare_repository_import/repository.rb +++ b/lib/gitlab/bare_repository_import/repository.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module BareRepositoryImport class Repository @@ -6,9 +8,12 @@ module Gitlab attr_reader :group_path, :project_name, :repo_path def initialize(root_path, repo_path) + unless root_path.ends_with?('/') + root_path = "#{root_path}/" + end + @root_path = root_path @repo_path = repo_path - @root_path << '/' unless root_path.ends_with?('/') full_path = if hashed? && !wiki? diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index a7dfccea2f6..45e550b3450 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module BitbucketImport class Importer diff --git a/lib/gitlab/bitbucket_import/project_creator.rb b/lib/gitlab/bitbucket_import/project_creator.rb index d94f70fd1fb..11070a68e02 100644 --- a/lib/gitlab/bitbucket_import/project_creator.rb +++ b/lib/gitlab/bitbucket_import/project_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module BitbucketImport class ProjectCreator diff --git a/lib/gitlab/bitbucket_server_import/project_creator.rb b/lib/gitlab/bitbucket_server_import/project_creator.rb index 35e8cd7e0ab..48ca4951957 100644 --- a/lib/gitlab/bitbucket_server_import/project_creator.rb +++ b/lib/gitlab/bitbucket_server_import/project_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module BitbucketServerImport class ProjectCreator diff --git a/lib/gitlab/cache/ci/project_pipeline_status.rb b/lib/gitlab/cache/ci/project_pipeline_status.rb index add048d671e..b369b9e7600 100644 --- a/lib/gitlab/cache/ci/project_pipeline_status.rb +++ b/lib/gitlab/cache/ci/project_pipeline_status.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This class is not backed by a table in the main database. # It loads the latest Pipeline for the HEAD of a repository, and caches that # in Redis. diff --git a/lib/gitlab/cache/request_cache.rb b/lib/gitlab/cache/request_cache.rb index b96e161a5b6..4c658dc0b8d 100644 --- a/lib/gitlab/cache/request_cache.rb +++ b/lib/gitlab/cache/request_cache.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Cache # See https://docs.gitlab.com/ee/development/utilities.html#requestcache diff --git a/lib/gitlab/checks/change_access.rb b/lib/gitlab/checks/change_access.rb index 7a4224e5bbe..49e7f7e1fd7 100644 --- a/lib/gitlab/checks/change_access.rb +++ b/lib/gitlab/checks/change_access.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class ChangeAccess diff --git a/lib/gitlab/checks/commit_check.rb b/lib/gitlab/checks/commit_check.rb index 7e0c34aada3..6dd74e8fb74 100644 --- a/lib/gitlab/checks/commit_check.rb +++ b/lib/gitlab/checks/commit_check.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class CommitCheck diff --git a/lib/gitlab/checks/force_push.rb b/lib/gitlab/checks/force_push.rb index 87af4a90572..263972923ed 100644 --- a/lib/gitlab/checks/force_push.rb +++ b/lib/gitlab/checks/force_push.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class ForcePush diff --git a/lib/gitlab/checks/lfs_integrity.rb b/lib/gitlab/checks/lfs_integrity.rb index 3f7adecc621..fa3dc1808df 100644 --- a/lib/gitlab/checks/lfs_integrity.rb +++ b/lib/gitlab/checks/lfs_integrity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class LfsIntegrity diff --git a/lib/gitlab/checks/matching_merge_request.rb b/lib/gitlab/checks/matching_merge_request.rb index 86f4aaeb4d3..71361b12d07 100644 --- a/lib/gitlab/checks/matching_merge_request.rb +++ b/lib/gitlab/checks/matching_merge_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class MatchingMergeRequest diff --git a/lib/gitlab/checks/post_push_message.rb b/lib/gitlab/checks/post_push_message.rb index 473c0385b34..492dbb5a596 100644 --- a/lib/gitlab/checks/post_push_message.rb +++ b/lib/gitlab/checks/post_push_message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class PostPushMessage diff --git a/lib/gitlab/checks/project_created.rb b/lib/gitlab/checks/project_created.rb index cec270d6a58..0058a402a62 100644 --- a/lib/gitlab/checks/project_created.rb +++ b/lib/gitlab/checks/project_created.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class ProjectCreated < PostPushMessage diff --git a/lib/gitlab/checks/project_moved.rb b/lib/gitlab/checks/project_moved.rb index 3a197078d08..cb3b7acaaad 100644 --- a/lib/gitlab/checks/project_moved.rb +++ b/lib/gitlab/checks/project_moved.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Gitlab module Checks class ProjectMoved < PostPushMessage