Skip to content

Commit

Permalink
rubocop: Style/PreferredHashMethods compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Aug 11, 2016
1 parent e241c0b commit 75bb674
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 30 deletions.
16 changes: 0 additions & 16 deletions .rubocop_todo.yml
Expand Up @@ -788,22 +788,6 @@ Style/PercentLiteralDelimiters:
- 'lib/yard/templates/helpers/html_helper.rb'
- 'spec/tags/directives_spec.rb'

# Offense count: 12
# Cop supports --auto-correct.
Style/PreferredHashMethods:
Exclude:
- 'benchmarks/builtins_vs_eval.rb'
- 'lib/yard/cli/command_parser.rb'
- 'lib/yard/code_objects/class_object.rb'
- 'lib/yard/code_objects/method_object.rb'
- 'lib/yard/i18n/pot_generator.rb'
- 'lib/yard/parser/ruby/ast_node.rb'
- 'lib/yard/parser/ruby/ruby_parser.rb'
- 'lib/yard/parser/source_parser.rb'
- 'lib/yard/serializers/file_system_serializer.rb'
- 'spec/core_ext/symbol_hash_spec.rb'
- 'spec/registry_spec.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/builtins_vs_eval.rb
Expand Up @@ -4,7 +4,7 @@
TIMES = (ARGV[0] || 10_000).to_i

def bench_builtins(name)
YARD::CodeObjects::BUILTIN_EXCEPTIONS_HASH.has_key? name
YARD::CodeObjects::BUILTIN_EXCEPTIONS_HASH.key? name
end

def bench_eval(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/cli/command_parser.rb
Expand Up @@ -67,7 +67,7 @@ def run(*args)
command_name = args.first.to_sym
args.shift
end
if commands.has_key?(command_name)
if commands.key?(command_name)
return commands[command_name].run(*args)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/code_objects/class_object.rb
Expand Up @@ -32,7 +32,7 @@ def initialize(namespace, name, *args, &block)
#
# @return [Boolean] whether the object represents a Ruby exception
def is_exception?
inheritance_tree.reverse.any? {|o| BUILTIN_EXCEPTIONS_HASH.has_key? o.path }
inheritance_tree.reverse.any? {|o| BUILTIN_EXCEPTIONS_HASH.key? o.path }
end

# Returns the inheritance tree of the object including self.
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/code_objects/method_object.rb
Expand Up @@ -119,7 +119,7 @@ def is_attribute?
# @return [Boolean] whether the object is an alias
def is_alias?
return false unless namespace.is_a?(NamespaceObject)
namespace.aliases.has_key? self
namespace.aliases.key? self
end

# Tests boolean {#explicit} value.
Expand Down
3 changes: 2 additions & 1 deletion lib/yard/core_ext/symbol_hash.rb
Expand Up @@ -55,7 +55,8 @@ def delete(key) super(key.to_sym) end
# Tests if a symbolized key exists
# @param [#to_sym] key the key to test
# @return [Boolean] whether the key exists
def has_key?(key) super(key.to_sym) end
def key?(key) super(key.to_sym) end
alias has_key? key?

# Updates the object with the contents of another Hash object.
# This method modifies the original SymbolHash object
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/i18n/pot_generator.rb
Expand Up @@ -190,7 +190,7 @@ def register_message(id)
end

def extract_documents(object)
return if @extracted_objects.has_key?(object)
return if @extracted_objects.key?(object)

@extracted_objects[object] = true
case object
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/parser/ruby/ast_node.rb
Expand Up @@ -128,7 +128,7 @@ def self.node_class_for(type)
ReferenceNode
elsif type.to_s =~ /_literal\Z/
LiteralNode
elsif KEYWORDS.has_key?(type)
elsif KEYWORDS.key?(type)
KeywordNode
else
AstNode
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/parser/ruby/ruby_parser.rb
Expand Up @@ -157,7 +157,7 @@ def on_#{event}(list, item)
list
end
eof
elsif MAPPINGS.has_key?(event)
elsif MAPPINGS.key?(event)
module_eval(<<-eof, __FILE__, __LINE__ + 1)
begin; undef on_#{event}; rescue NameError; end
def on_#{event}(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/parser/source_parser.rb
Expand Up @@ -421,7 +421,7 @@ def parse(content = __FILE__)
checksum = Registry.checksum_for(content)
return if Registry.checksums[file] == checksum

if Registry.checksums.has_key?(file)
if Registry.checksums.key?(file)
log.info "File '#{file}' was modified, re-processing..."
end
Registry.checksums[@file] = checksum
Expand Down
2 changes: 1 addition & 1 deletion lib/yard/serializers/file_system_serializer.rb
Expand Up @@ -28,7 +28,7 @@ def initialize(opts = {})
super
@name_map = nil
@basepath = (options[:basepath] || 'doc').to_s
@extension = (options.has_key?(:extension) ? options[:extension] : 'html').to_s
@extension = (options.key?(:extension) ? options[:extension] : 'html').to_s
end

# Serializes object with data to its serialized path (prefixed by the +#basepath+).
Expand Down
6 changes: 3 additions & 3 deletions spec/core_ext/symbol_hash_spec.rb
Expand Up @@ -27,12 +27,12 @@
end
end

describe "#has_key?" do
describe "#key?" do
it "returns same result for String or Symbol" do
h = SymbolHash.new
h[:test] = 1
expect(h.has_key?(:test)).to be true
expect(h.has_key?('test')).to be true
expect(h.key?(:test)).to be true
expect(h.has_key?('test')).to be true # rubocop:disable Style/PreferredHashMethods
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/registry_spec.rb
Expand Up @@ -340,7 +340,7 @@ def self.Bar; end
Registry.load!(File.dirname(__FILE__) + '/serializers/data/serialized_yardoc')
baz = Registry.at('Foo#baz')
expect(Registry.at('Foo').aliases.keys).to include(baz)
expect(Registry.at('Foo').aliases.has_key?(baz)).to be true
expect(Registry.at('Foo').aliases.key?(baz)).to be true
end
end

Expand Down

0 comments on commit 75bb674

Please sign in to comment.