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

Commit

Permalink
[RuboCop] Fix Style/MutableConstant
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Feb 1, 2016
1 parent 8b64c97 commit b1afbe3
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 64 deletions.
15 changes: 0 additions & 15 deletions .rubocop_todo.yml
Expand Up @@ -183,21 +183,6 @@ Style/ModuleFunction:
Style/MultilineMethodCallIndentation:
Enabled: false

# Offense count: 24
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'lib/bundler/cli.rb'
- 'lib/bundler/cli/gem.rb'
- 'lib/bundler/fetcher.rb'
- 'lib/bundler/gem_helpers.rb'
- 'lib/bundler/lockfile_parser.rb'
- 'lib/bundler/runtime.rb'
- 'lib/bundler/settings.rb'
- 'lib/bundler/source/path.rb'
- 'lib/bundler/ui/shell.rb'
- 'lib/bundler/version.rb'

# Offense count: 8
Style/NestedParenthesizedCalls:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli.rb
Expand Up @@ -4,7 +4,7 @@
module Bundler
class CLI < Thor
include Thor::Actions
AUTO_INSTALL_CMDS = %w(show binstubs outdated exec open console licenses clean)
AUTO_INSTALL_CMDS = %w(show binstubs outdated exec open console licenses clean).freeze

def self.start(*)
super
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/cli/gem.rb
Expand Up @@ -5,7 +5,7 @@ class CLI::Gem
TEST_FRAMEWORK_VERSIONS = {
"rspec" => "3.0",
"minitest" => "5.0"
}
}.freeze

attr_reader :options, :gem_name, :thor, :name, :target

Expand Down
1 change: 1 addition & 0 deletions lib/bundler/endpoint_specification.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
# used for Creating Specifications from the Gemcutter Endpoint
class EndpointSpecification < Gem::Specification
Expand Down
14 changes: 7 additions & 7 deletions lib/bundler/fetcher.rb
Expand Up @@ -53,13 +53,13 @@ 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]
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]
: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)

Expand Down Expand Up @@ -150,10 +150,10 @@ def use_api

fetchers.shift until fetchers.first.available?

if remote_uri.scheme == "file" || Bundler::Fetcher.disable_endpoint
@use_api = false
@use_api = if remote_uri.scheme == "file" || Bundler::Fetcher.disable_endpoint
false
else
@use_api = fetchers.first.api_fetcher?
fetchers.first.api_fetcher?
end
end

Expand Down Expand Up @@ -207,7 +207,7 @@ def inspect

private

FETCHERS = [CompactIndex, Dependency, Index]
FETCHERS = [CompactIndex, Dependency, Index].freeze

def cis
env_cis = {
Expand Down Expand Up @@ -267,7 +267,7 @@ def gemspec_cached_path(spec_file_name)
Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EAGAIN,
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
Net::HTTP::Persistent::Error, Zlib::BufError
]
].freeze

def bundler_cert_store
store = OpenSSL::X509::Store.new
Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/gem_helpers.rb
@@ -1,6 +1,6 @@
module Bundler
module GemHelpers
GENERIC_CACHE = {}
GENERIC_CACHE = {}.freeze
GENERICS = [
[Gem::Platform.new("java"), Gem::Platform.new("java")],
[Gem::Platform.new("mswin32"), Gem::Platform.new("mswin32")],
Expand All @@ -9,7 +9,7 @@ module GemHelpers
[Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw32")],
[Gem::Platform.new("x86_64-mingw32"), Gem::Platform.new("x64-mingw32")],
[Gem::Platform.new("mingw32"), Gem::Platform.new("x86-mingw32")]
]
].freeze

def generic(p)
return p if p == Gem::Platform::RUBY
Expand Down
23 changes: 12 additions & 11 deletions lib/bundler/lockfile_parser.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "strscan"

# Some versions of the Bundler 1.1 RC series introduced corrupted
Expand All @@ -14,16 +15,16 @@ module Bundler
class LockfileParser
attr_reader :sources, :dependencies, :specs, :platforms, :bundler_version, :ruby_version

BUNDLED = "BUNDLED WITH"
DEPENDENCIES = "DEPENDENCIES"
PLATFORMS = "PLATFORMS"
RUBY = "RUBY VERSION"
GIT = "GIT"
GEM = "GEM"
PATH = "PATH"
SPECS = " specs:"
BUNDLED = "BUNDLED WITH".freeze
DEPENDENCIES = "DEPENDENCIES".freeze
PLATFORMS = "PLATFORMS".freeze
RUBY = "RUBY VERSION".freeze
GIT = "GIT".freeze
GEM = "GEM".freeze
PATH = "PATH".freeze
SPECS = " specs:".freeze
OPTIONS = /^ ([a-z]+): (.*)$/i
SOURCE = [GIT, GEM, PATH]
SOURCE = [GIT, GEM, PATH].freeze

def initialize(lockfile)
@platforms = []
Expand Down Expand Up @@ -89,7 +90,7 @@ def warn_for_outdated_bundler_version
GIT => Bundler::Source::Git,
GEM => Bundler::Source::Rubygems,
PATH => Bundler::Source::Path,
}
}.freeze

def parse_source(line)
case line
Expand Down Expand Up @@ -134,7 +135,7 @@ def parse_source(line)
end
end

NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'
NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
NAME_VERSION_2 = /^ {2}#{NAME_VERSION}(!)?$/
NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
NAME_VERSION_6 = /^ {6}#{NAME_VERSION}$/
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/runtime.rb
Expand Up @@ -52,7 +52,7 @@ def setup(*groups)
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
/^dlopen\([^)]*\): Library not loaded: (.+)$/i,
]
].freeze

def require(*groups)
groups.map!(&:to_sym)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/settings.rb
Expand Up @@ -4,7 +4,7 @@ module Bundler
class Settings
BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check disable_shared_gems ignore_messages gem.mit gem.coc silence_root_warning).freeze
NUMBER_KEYS = %w(retry timeout redirect ssl_verify_mode).freeze
DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 }
DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 }.freeze

def initialize(root = nil)
@root = root
Expand Down
3 changes: 2 additions & 1 deletion lib/bundler/source/path.rb
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module Bundler
class Source
class Path < Source
Expand All @@ -7,7 +8,7 @@ class Path < Source
attr_writer :name
attr_accessor :version

DEFAULT_GLOB = "{,*,*/*}.gemspec"
DEFAULT_GLOB = "{,*,*/*}.gemspec".freeze

def initialize(options)
@options = options
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/ui/shell.rb
Expand Up @@ -3,7 +3,7 @@
module Bundler
module UI
class Shell
LEVELS = %w(silent error warn confirm info debug)
LEVELS = %w(silent error warn confirm info debug).freeze

attr_writer :shell

Expand Down
3 changes: 2 additions & 1 deletion lib/bundler/version.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
module Bundler
# We're doing this because we might write tests that deal
# with other versions of bundler and we are unsure how to
# handle this better.
VERSION = "1.12.0.pre" unless defined?(::Bundler::VERSION)
VERSION = "1.12.0.pre".freeze unless defined?(::Bundler::VERSION)
end
12 changes: 6 additions & 6 deletions spec/bundler/fetcher/dependency_spec.rb
Expand Up @@ -92,7 +92,7 @@
it "should return a hash with the remote_uri and the list of specs" do
expect(subject.specs(gem_names, full_dependency_list, last_spec_list)).to eq([
["top", gem_version2, "ruby", faraday],
["boulder", gem_version1, "ruby", resque]
["boulder", gem_version1, "ruby", resque],
])
end
end
Expand Down Expand Up @@ -225,20 +225,20 @@
[
{
:dependencies => {
"resque" => "req3,req4"
"resque" => "req3,req4",
},
:name => "typhoeus",
:number => "1.0.1",
:platform => "ruby"
:platform => "ruby",
},
{
:dependencies => {
"faraday" => "req1,req2"
"faraday" => "req1,req2",
},
:name => "grape",
:number => "2.0.2",
:platform => "jruby"
}
:platform => "jruby",
},
]
end

Expand Down
4 changes: 2 additions & 2 deletions spec/bundler/source_spec.rb
Expand Up @@ -85,15 +85,15 @@ class ExampleSource < Bundler::Source
let(:spec) { double(:spec, :source => subject) }

it "should return true" do
expect(subject.can_lock? spec).to be_truthy
expect(subject.can_lock?(spec)).to be_truthy
end
end

context "when the passed spec's source is not equivalent" do
let(:spec) { double(:spec, :source => double(:other_source)) }

it "should return false" do
expect(subject.can_lock? spec).to be_falsey
expect(subject.can_lock?(spec)).to be_falsey
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/bundler/ssl_certs/certificate_manager_spec.rb
Expand Up @@ -3,8 +3,8 @@

describe Bundler::SSLCerts::CertificateManager do
let(:rubygems_path) { root }
let(:stub_cert) { File.join("#{root}", "lib", "rubygems", "ssl_certs", "ssl-cert.pem") }
let(:rubygems_certs_dir) { File.join("#{root}", "lib", "rubygems", "ssl_certs") }
let(:stub_cert) { File.join(root.to_s, "lib", "rubygems", "ssl_certs", "ssl-cert.pem") }
let(:rubygems_certs_dir) { File.join(root.to_s, "lib", "rubygems", "ssl_certs") }

subject { described_class.new(rubygems_path) }

Expand All @@ -15,7 +15,7 @@
end

after do
rubygems_dir = File.join("#{root}", "lib", "rubygems")
rubygems_dir = File.join(root.to_s, "lib", "rubygems")
FileUtils.rm_rf(rubygems_dir)
end

Expand Down Expand Up @@ -50,7 +50,7 @@
describe "#up_to_date?" do
context "when bundler certs and rubygems certs are the same" do
before do
bundler_certs = Dir[File.join("#{root}", "lib", "bundler", "ssl_certs", "*.pem")]
bundler_certs = Dir[File.join(root.to_s, "lib", "bundler", "ssl_certs", "*.pem")]
FileUtils.rm(stub_cert)
FileUtils.cp(bundler_certs, rubygems_certs_dir)
end
Expand Down
12 changes: 6 additions & 6 deletions spec/support/artifice/compact_index.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require File.expand_path("../endpoint", __FILE__)

$LOAD_PATH.unshift "#{Dir[base_system_gems.join("gems/compact_index*/lib")].first}"
$LOAD_PATH.unshift Dir[base_system_gems.join("gems/compact_index*/lib")].first.to_s
require "compact_index"

class CompactIndexAPI < Endpoint
Expand Down Expand Up @@ -28,11 +29,10 @@ def etag_response
def not_modified?(checksum)
etags = parse_etags(request.env["HTTP_IF_NONE_MATCH"])

if etags.include?(checksum)
headers "ETag" => quote(checksum)
status 304
body ""
end
return unless etags.include?(checksum)
headers "ETag" => quote(checksum)
status 304
body ""
end

def requested_range_for(response_body)
Expand Down
7 changes: 3 additions & 4 deletions spec/support/artifice/compact_index_creds_diff_host.rb
Expand Up @@ -13,10 +13,9 @@ def authorized?
end

def protected!
unless authorized?
response["WWW-Authenticate"] = %(Basic realm="Testing HTTP Auth")
throw(:halt, [401, "Not authorized\n"])
end
return if authorized?
response["WWW-Authenticate"] = %(Basic realm="Testing HTTP Auth")
throw(:halt, [401, "Not authorized\n"])
end
end

Expand Down

0 comments on commit b1afbe3

Please sign in to comment.