Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Compatibility with frozen string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Feb 1, 2016
1 parent b1afbe3 commit 7ae0728
Show file tree
Hide file tree
Showing 256 changed files with 311 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Expand Up @@ -31,6 +31,9 @@ Style/Alias:
Style/AlignParameters:
EnforcedStyle: with_fixed_indentation

Style/FrozenStringLiteralComment:
EnforcedStyle: always

Style/MultilineBlockChain:
Enabled: false

Expand Down
9 changes: 0 additions & 9 deletions .rubocop_todo.yml
Expand Up @@ -140,15 +140,6 @@ Style/ExtraSpacing:
Exclude:
- 'lib/bundler/cli.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: when_needed, always
Style/FrozenStringLiteralComment:
Exclude:
- 'lib/bundler/index.rb'
- 'spec/runtime/inline_spec.rb'

# Offense count: 4
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
Expand Down
1 change: 1 addition & 0 deletions Rakefile
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
$:.unshift File.expand_path("../lib", __FILE__)
require "shellwords"
require "benchmark"
Expand Down
1 change: 1 addition & 0 deletions bin/rake
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "rubygems"

Expand Down
1 change: 1 addition & 0 deletions bin/rspec
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "rubygems"

Expand Down
1 change: 1 addition & 0 deletions bin/rubocop
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "rubygems"

Expand Down
1 change: 1 addition & 0 deletions bundler.gemspec
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true
lib = File.expand_path("../lib/", __FILE__)
$:.unshift lib unless $:.include?(lib)
require "bundler/version"
Expand Down
4 changes: 3 additions & 1 deletion exe/bundle
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Exit cleanly from an early interrupt
Signal.trap("INT") { exit 1 }
Expand All @@ -7,7 +8,8 @@ require "bundler"
# Check if an older version of bundler is installed
$LOAD_PATH.each do |path|
next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9
err = "Looks like you have a version of bundler that's older than 0.9.\n"
err = String.new
err << "Looks like you have a version of bundler that's older than 0.9.\n"
err << "Please remove your old versions.\n"
err << "An easy way to do this is by running `gem cleanup bundler`."
abort(err)
Expand Down
1 change: 1 addition & 0 deletions exe/bundle_ruby
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

Signal.trap("INT") { exit 1 }

Expand Down
4 changes: 3 additions & 1 deletion exe/bundler
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Exit cleanly from an early interrupt
Signal.trap("INT") { exit 1 }
Expand All @@ -7,7 +8,8 @@ require "bundler"
# Check if an older version of bundler is installed
$LOAD_PATH.each do |path|
next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9
err = "Looks like you have a version of bundler that's older than 0.9.\n"
err = String.new
err << "Looks like you have a version of bundler that's older than 0.9.\n"
err << "Please remove your old versions.\n"
err << "An easy way to do this is by running `gem cleanup bundler`."
abort(err)
Expand Down
4 changes: 3 additions & 1 deletion lib/bundler.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "fileutils"
require "pathname"
require "rbconfig"
Expand Down Expand Up @@ -385,7 +386,8 @@ def eval_gemspec(path, contents)
eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s)
rescue ScriptError, StandardError => e
original_line = e.backtrace.find {|line| line.include?(path.to_s) }
msg = "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
msg = String.new
msg << "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
msg << " from\n #{original_line}" if original_line
msg << "\n"

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/capistrano.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# Capistrano task for Bundler.
#
# Just add "require 'bundler/capistrano'" in your Capistrano deploy.rb, and
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler"
require "bundler/vendored_thor"

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/binstubs.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/cli/common"

module Bundler
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/cache.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Cache
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/check.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Check
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/clean.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Clean
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/common.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
module CLI::Common
def self.without_groups_message
Expand Down
3 changes: 2 additions & 1 deletion lib/bundler/cli/config.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Config
attr_reader :name, :options, :scope, :thor
Expand All @@ -11,7 +12,7 @@ def initialize(options, args, thor)
@scope = "global"
return unless peek && peek.start_with?("--")
@name = args.shift
@scope = $'
@scope = peek[2..-1]
end

def run
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/console.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Console
attr_reader :options, :group
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/exec.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/current_ruby"

module Bundler
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/gem.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "pathname"

module Bundler
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/init.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Init
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/inject.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Inject
attr_reader :options, :name, :version, :gems
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/install.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Install
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/lock.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Lock
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/open.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/cli/common"
require "shellwords"

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/outdated.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/cli/common"

module Bundler
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/package.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Package
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/platform.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Platform
attr_reader :options
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/show.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/cli/common"

module Bundler
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/update.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Update
attr_reader :options, :gems
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/cli/viz.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class CLI::Viz
attr_reader :options, :gem_name
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/constants.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
WINDOWS = RbConfig::CONFIG["host_os"] =~ /(msdos|mswin|djgpp|mingw)/
FREEBSD = RbConfig::CONFIG["host_os"] =~ /bsd/
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/current_ruby.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
# Returns current version of Ruby
#
Expand Down
10 changes: 6 additions & 4 deletions lib/bundler/definition.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/lockfile_parser"
require "digest/sha1"
require "set"
Expand Down Expand Up @@ -347,12 +348,13 @@ def to_lock
end

def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
msg = "You are trying to install in deployment mode after changing\n" \
"your Gemfile. Run `bundle install` elsewhere and add the\n" \
"updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control."
msg = String.new
msg << "You are trying to install in deployment mode after changing\n" \
"your Gemfile. Run `bundle install` elsewhere and add the\n" \
"updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control."

unless explicit_flag
msg += "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \
msg << "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \
"freeze \nby running `bundle install --no-deployment`."
end

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/dep_proxy.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class DepProxy
attr_reader :__platform, :dep
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/dependency.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "rubygems/dependency"
require "bundler/shared_helpers"
require "bundler/rubygems_ext"
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/deployment.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class Deployment
def self.define_task(context, task_method = :task, opts = {})
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/deprecate.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
if defined? ::Deprecate
Deprecate = ::Deprecate
Expand Down
6 changes: 4 additions & 2 deletions lib/bundler/dsl.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/dependency"
require "bundler/ruby_dsl"

Expand Down Expand Up @@ -345,7 +346,8 @@ def normalize_group_options(opts, groups)
def validate_keys(command, opts, valid_keys)
invalid_keys = opts.keys - valid_keys
if invalid_keys.any?
message = "You passed #{invalid_keys.map {|k| ":" + k }.join(", ")} "
message = String.new
message << "You passed #{invalid_keys.map {|k| ":" + k }.join(", ")} "
message << if invalid_keys.size > 1
"as options for #{command}, but they are invalid."
else
Expand Down Expand Up @@ -450,7 +452,7 @@ def to_s
@to_s ||= begin
trace_line, description = parse_line_number_from_description

m = "\n[!] "
m = String.new("\n[!] ")
m << description
m << ". Bundler cannot continue.\n"

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/env.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/rubygems_integration"
require "bundler/source/git/git_proxy"

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/environment.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class Environment
attr_reader :root
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/errors.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class BundlerError < StandardError
def self.status_code(code)
Expand Down
11 changes: 7 additions & 4 deletions lib/bundler/fetcher.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/vendored_persistent"
require "cgi"
require "securerandom"
Expand Down Expand Up @@ -53,15 +54,17 @@ def initialize(remote_uri)

# Exceptions classes that should bypass retry attempts. If your password didn't work the
# first time, it's not going to the third time.
FAIL_ERRORS = [AuthenticationRequiredError, BadAuthenticationError, FallbackError].freeze
NET_ERRORS = [:HTTPBadGateway, :HTTPBadRequest, :HTTPFailedDependency,
:HTTPForbidden, :HTTPInsufficientStorage, :HTTPMethodNotAllowed,
:HTTPMovedPermanently, :HTTPNoContent, :HTTPNotFound,
:HTTPNotImplemented, :HTTPPreconditionFailed, :HTTPRequestEntityTooLarge,
:HTTPRequestURITooLong, :HTTPUnauthorized, :HTTPUnprocessableEntity,
:HTTPUnsupportedMediaType, :HTTPVersionNotSupported].freeze
FAIL_ERRORS << Gem::Requirement::BadRequirementError if defined?(Gem::Requirement::BadRequirementError)
FAIL_ERRORS.push(*NET_ERRORS.map {|e| SharedHelpers.const_get_safely(e, Net) }.compact)
FAIL_ERRORS = begin
fail_errors = [AuthenticationRequiredError, BadAuthenticationError, FallbackError]
fail_errors << Gem::Requirement::BadRequirementError if defined?(Gem::Requirement::BadRequirementError)
fail_errors.push(*NET_ERRORS.map {|e| SharedHelpers.const_get_safely(e, Net) }.compact)
end.freeze

class << self
attr_accessor :disable_endpoint, :api_timeout, :redirect_limit, :max_retries
Expand Down Expand Up @@ -161,7 +164,7 @@ def user_agent
@user_agent ||= begin
ruby = Bundler::RubyVersion.system

agent = "bundler/#{Bundler::VERSION}"
agent = String.new("bundler/#{Bundler::VERSION}")
agent << " rubygems/#{Gem::VERSION}"
agent << " ruby/#{ruby.version}"
agent << " (#{ruby.host})"
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/fetcher/base.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class Fetcher
class Base
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/fetcher/compact_index.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/fetcher/base"
require "bundler/worker"

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/fetcher/dependency.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/fetcher/base"
require "cgi"

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/fetcher/downloader.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class Fetcher
class Downloader
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/fetcher/index.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "bundler/fetcher/base"
require "rubygems/remote_fetcher"

Expand Down
3 changes: 2 additions & 1 deletion lib/bundler/friendly_errors.rb
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true
require "cgi"
require "bundler/vendored_thor"

Expand Down Expand Up @@ -68,7 +69,7 @@ def request_issue_report_for(e)
Error details

#{e.class}: #{e.message}
#{e.backtrace.join("\n ")}
#{e.backtrace.join("\n ")}

#{Bundler::Env.new.report(:print_gemfile => false, :print_gemspecs => false).gsub(/\n/, "\n ").strip}
--- TEMPLATE END ----------------------------------------------------------------
Expand Down

0 comments on commit 7ae0728

Please sign in to comment.