Skip to content

Commit

Permalink
rubocop: fix offences of the Style/MutableConstant cop
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo committed Mar 2, 2019
1 parent 09596c1 commit 66b6208
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 63 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,6 @@ Style/MultipleComparison:
Exclude:
- 'lib/pry/indent.rb'

# Offense count: 48
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Enabled: false

# Offense count: 23
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down
6 changes: 3 additions & 3 deletions lib/pry/code/code_file.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Pry
class CodeFile
DEFAULT_EXT = '.rb'
DEFAULT_EXT = '.rb'.freeze

# List of all supported languages.
# @return [Hash]
Expand All @@ -19,11 +19,11 @@ class CodeFile
%w(.yaml .yml) => :yaml,
%w(.cpp .hpp .cc .h .cxx) => :cpp,
%w(.rb .ru .irbrc .gemspec .pryrc .rake) => :ruby,
}
}.freeze

FILES = {
%w(Gemfile Rakefile Guardfile Capfile) => :ruby
}
}.freeze

# Store the current working directory. This allows show-source etc. to work if
# your process has changed directory since boot. [Issue #675]
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/gem_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GemSearch < Pry::ClassCommand
Search for a gem with the rubygems.org HTTP API
BANNER

API_ENDPOINT = 'https://rubygems.org/api/v1/search.json'
API_ENDPOINT = 'https://rubygems.org/api/v1/search.json'.freeze

def setup
require 'json' unless defined?(JSON)
Expand Down
6 changes: 3 additions & 3 deletions lib/pry/commands/gem_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ class Command
class GemStat < Pry::ClassCommand
require 'json'
require 'net/http'
STAT_HOST = "rubygems.org"
STAT_HOST = "rubygems.org".freeze
STAT_PORT = 443
STAT_PATH = "/api/v1/gems/%s.json"
FAIL_WHALE = <<-FAILWHALE
STAT_PATH = "/api/v1/gems/%s.json".freeze
FAIL_WHALE = <<-FAILWHALE.freeze
W W W
W W W W
'. W
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/ls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Ls < Pry::ClassCommand
unloaded_constant_color: :yellow, # Any constant that is still in .autoload? state
separator: " ",
ceiling: [Object, Module, Class]
}
}.freeze

match 'ls'
group 'Context'
Expand Down
7 changes: 5 additions & 2 deletions lib/pry/commands/ls/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class Pry
class Command
class Ls < Pry::ClassCommand
class Constants < Pry::Command::Ls::Formatter
DEPRECATED_CONSTANTS = [:Data, :Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE]
DEPRECATED_CONSTANTS << :JavaPackageModuleTemplate if Helpers::Platform.jruby?
DEPRECATED_CONSTANTS = [
:Data, :Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE
].tap do |constants|
constants << :JavaPackageModuleTemplate if Helpers::Platform.jruby?
end
include Pry::Command::Ls::Interrogatable

def initialize(interrogatee, no_user_opts, opts, _pry_)
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/commands/ls/globals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class Globals < Pry::Command::Ls::Formatter
$FIELD_SEPARATOR $FILENAME $FS $IGNORECASE $INPUT_LINE_NUMBER
$INPUT_RECORD_SEPARATOR $KCODE $LOADED_FEATURES $LOAD_PATH $NR $OFS
$ORS $OUTPUT_FIELD_SEPARATOR $OUTPUT_RECORD_SEPARATOR $PID $PROCESS_ID
$PROGRAM_NAME $RS $VERBOSE $deferr $defout $stderr $stdin $stdout)
$PROGRAM_NAME $RS $VERBOSE $deferr $defout $stderr $stdin $stdout).freeze

# `$SAFE` and `$?` are thread-local, the exception stuff only works in a
# rescue clause, everything else is basically a local variable with a `$`
# in its name.
PSEUDO_GLOBALS =
%w($! $' $& $` $@ $? $+ $_ $~ $1 $2 $3 $4 $5 $6 $7 $8 $9
$CHILD_STATUS $SAFE $ERROR_INFO $ERROR_POSITION $LAST_MATCH_INFO
$LAST_PAREN_MATCH $LAST_READ_LINE $MATCH $POSTMATCH $PREMATCH)
$LAST_PAREN_MATCH $LAST_READ_LINE $MATCH $POSTMATCH $PREMATCH).freeze

def initialize(opts, _pry_)
super(_pry_)
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/config/behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Behavior
Pry::Prompt, Pry::Config::Lazy
].freeze

INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/.freeze
ReservedKeyError = Class.new(RuntimeError)

#
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/config/convenience.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Convenience
:editor,
:memory_size,
:extra_sticky_locals
]
].freeze

def config_shortcut(*names)
names.each do |name|
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/core_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Pry
# friends).
#
# @see Object#__binding__
BINDING_METHOD_IMPL = [<<-METHOD, __FILE__, __LINE__ + 1]
BINDING_METHOD_IMPL = [<<-METHOD, __FILE__, __LINE__ + 1].freeze
# Get a binding with 'self' set to self, and no locals.
#
# The default definee is determined by the context in which the
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.===(exception)
# Don't catch these exceptions
DEFAULT_UNRESCUED_EXCEPTIONS = [SystemExit,
SignalException,
Pry::TooSafeException]
Pry::TooSafeException].freeze
DEFAULT_EXCEPTION_WHITELIST = DEFAULT_UNRESCUED_EXCEPTIONS
if Object.respond_to?(:deprecate_constant)
deprecate_constant :DEFAULT_EXCEPTION_WHITELIST
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/helpers/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Text
"magenta" => 5,
"cyan" => 6,
"white" => 7
}
}.freeze

COLORS.each_pair do |color, value|
define_method color do |text|
Expand Down
12 changes: 6 additions & 6 deletions lib/pry/indent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UnparseableNestingError < StandardError; end
attr_reader :stack

# The amount of spaces to insert for each indent level.
SPACES = ' '
SPACES = ' '.freeze

# Hash containing all the tokens that should increase the indentation
# level. The keys of this hash are open tokens, the values the matching
Expand All @@ -42,14 +42,14 @@ class UnparseableNestingError < StandardError; end
'[' => ']',
'{' => '}',
'(' => ')'
}
}.freeze

# Which tokens can either be open tokens, or appear as modifiers on
# a single-line.
SINGLELINE_TOKENS = %w(if while until unless rescue)
SINGLELINE_TOKENS = %w(if while until unless rescue).freeze

# Which tokens can be followed by an optional "do" keyword.
OPTIONAL_DO_TOKENS = %w(for while until)
OPTIONAL_DO_TOKENS = %w(for while until).freeze

# Collection of token types that should be ignored. Without this list
# keywords such as "class" inside strings would cause the code to be
Expand All @@ -58,7 +58,7 @@ class UnparseableNestingError < StandardError; end
# :pre_constant and :preserved_constant are the CodeRay 0.9.8 and 1.0.0
# classifications of "true", "false", and "nil".
IGNORE_TOKENS = [:space, :content, :string, :method, :ident,
:constant, :pre_constant, :predefined_constant]
:constant, :pre_constant, :predefined_constant].freeze

# Tokens that indicate the end of a statement (i.e. that, if they appear
# directly before an "if" indicates that that if applies to the same line,
Expand All @@ -73,7 +73,7 @@ class UnparseableNestingError < StandardError; end

# Collection of tokens that should appear dedented even though they
# don't affect the surrounding code.
MIDWAY_TOKENS = %w(when else elsif ensure rescue)
MIDWAY_TOKENS = %w(when else elsif ensure rescue).freeze

# Clean the indentation of a fragment of ruby.
#
Expand Down
26 changes: 13 additions & 13 deletions lib/pry/input_completer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# Implements tab completion for Readline in Pry
class Pry
class InputCompleter
NUMERIC_REGEXP = /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
ARRAY_REGEXP = /^([^\]]*\])\.([^.]*)$/
SYMBOL_REGEXP = /^(:[^:.]*)$/
SYMBOL_METHOD_CALL_REGEXP = /^(:[^:.]+)\.([^.]*)$/
REGEX_REGEXP = /^(\/[^\/]*\/)\.([^.]*)$/
PROC_OR_HASH_REGEXP = /^([^\}]*\})\.([^.]*)$/
TOPLEVEL_LOOKUP_REGEXP = /^::([A-Z][^:\.\(]*)$/
CONSTANT_REGEXP = /^([A-Z][A-Za-z0-9]*)$/
CONSTANT_OR_METHOD_REGEXP = /^([A-Z].*)::([^:.]*)$/
HEX_REGEXP = /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/
GLOBALVARIABLE_REGEXP = /^(\$[^.]*)$/
VARIABLE_REGEXP = /^([^."].*)\.([^.]*)$/
NUMERIC_REGEXP = /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/.freeze
ARRAY_REGEXP = /^([^\]]*\])\.([^.]*)$/.freeze
SYMBOL_REGEXP = /^(:[^:.]*)$/.freeze
SYMBOL_METHOD_CALL_REGEXP = /^(:[^:.]+)\.([^.]*)$/.freeze
REGEX_REGEXP = /^(\/[^\/]*\/)\.([^.]*)$/.freeze
PROC_OR_HASH_REGEXP = /^([^\}]*\})\.([^.]*)$/.freeze
TOPLEVEL_LOOKUP_REGEXP = /^::([A-Z][^:\.\(]*)$/.freeze
CONSTANT_REGEXP = /^([A-Z][A-Za-z0-9]*)$/.freeze
CONSTANT_OR_METHOD_REGEXP = /^([A-Z].*)::([^:.]*)$/.freeze
HEX_REGEXP = /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/.freeze
GLOBALVARIABLE_REGEXP = /^(\$[^.]*)$/.freeze
VARIABLE_REGEXP = /^([^."].*)\.([^.]*)$/.freeze

ReservedWords = %w[
BEGIN END
Expand Down Expand Up @@ -41,7 +41,7 @@ def defined do
[] []= ^ ! != !~
].freeze

WORD_ESCAPE_STR = " \t\n\"\\'`><=;|&{("
WORD_ESCAPE_STR = " \t\n\"\\'`><=;|&{(".freeze

def initialize(input, pry = nil)
@pry = pry
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ class Inspector
but prints large objects as a smaller string.
DESCRIPTION
}
}
}.freeze
end
end
2 changes: 1 addition & 1 deletion lib/pry/object_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Pry
# Object paths are mostly relevant in the context of the `cd` command.
# @see https://github.com/pry/pry/wiki/State-navigation
class ObjectPath
SPECIAL_TERMS = ["", "::", ".", ".."]
SPECIAL_TERMS = ["", "::", ".", ".."].freeze

# @param [String] path_string The object path expressed as a string.
# @param [Array<Binding>] current_stack The current state of the binding
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/plugins.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Pry
class PluginManager
PRY_PLUGIN_PREFIX = /^pry-/
PRY_PLUGIN_PREFIX = /^pry-/.freeze

# Placeholder when no associated gem found, displays warning
class NoPlugin
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/pry_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Pry
else
'~/.config/pry/pryrc'
end
LOCAL_RC_FILE = "./.pryrc"
LOCAL_RC_FILE = "./.pryrc".freeze

class << self
extend Pry::Forwardable
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/slop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Slop
require_relative 'slop/option'
require_relative 'slop/commands'
include Enumerable
VERSION = '3.4.0'
VERSION = '3.4.0'.freeze

# The main Error class, all Exception classes inherit from this class.
class Error < StandardError; end
Expand Down Expand Up @@ -34,7 +34,7 @@ class InvalidCommandError < Error; end
optional_arguments: false,
multiple_switches: true,
longest_flag: 0
}
}.freeze

class << self
# items - The Array of items to extract options from (default: ARGV).
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/slop/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Option
required: false,
as: String,
autocreated: false
}
}.freeze

attr_reader :short, :long, :description, :config, :types
attr_accessor :count, :argument_in_value
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/testable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def self.included(mod)
should_load: false,
should_save: false
}
}
}.freeze
private_constant :TEST_DEFAULTS

#
Expand Down
4 changes: 2 additions & 2 deletions spec/completion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def self.name; :symboly_name; end
# Constant
module Mod
remove_const :Con if defined? Con
Con = 'Constant'
Con = 'Constant'.freeze
module Mod2
end
end
Expand Down Expand Up @@ -162,7 +162,7 @@ module Baz
# Constant
module Mod
remove_const :Con if defined? Con
Con = 'Constant'
Con = 'Constant'.freeze
module Mod2
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/pry_defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ def get_prompts(pry)
end

describe "view_clip used for displaying an object in a truncated format" do
DEFAULT_OPTIONS = {
max_length: 60
}
MAX_LENGTH = DEFAULT_OPTIONS[:max_length]
before do
stub_const('DEFAULT_OPTIONS', max_length: 60)
stub_const('MAX_LENGTH', 60)
end

describe "given an object with an #inspect string" do
it "returns the #<> format of the object (never use inspect)" do
Expand Down
11 changes: 5 additions & 6 deletions spec/pryrc_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
describe Pry do
describe 'loading rc files' do
before do
Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
Pry::LOCAL_RC_FILE.replace "spec/fixtures/testrc/../testrc"
stub_const('Pry::HOME_RC_FILE', 'spec/fixtures/testrc')
stub_const('Pry::LOCAL_RC_FILE', 'spec/fixtures/testrc/../testrc')

Pry.instance_variable_set(:@initial_session, true)
Pry.config.should_load_rc = true
Pry.config.should_load_local_rc = true
end

after do
Pry::HOME_RC_FILE.replace "~/.pryrc"
Pry::LOCAL_RC_FILE.replace "./.pryrc"
Pry.config.should_load_rc = false
Object.remove_const(:TEST_RC) if defined?(TEST_RC)
end
Expand All @@ -26,8 +25,8 @@
# Resolving symlinks doesn't work on jruby 1.9 [jruby issue #538]
unless Pry::Helpers::Platform.jruby_19?
it "should not load the rc file twice if it's symlinked differently" do
Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
Pry::LOCAL_RC_FILE.replace "spec/fixtures/testlinkrc"
stub_const('Pry::HOME_RC_FILE', 'spec/fixtures/testrc')
stub_const('Pry::LOCAL_RC_FILE', 'spec/fixtures/testlinkrc')

Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)

Expand Down

0 comments on commit 66b6208

Please sign in to comment.