Skip to content

Commit

Permalink
Rename Style/DeprecatedHashMethods to Style/PreferredHashMethods (r…
Browse files Browse the repository at this point in the history
…ubocop#3226)

Fixes rubocop#3224

As stated by Matz in the discussion in rubocop#3224, the methods
`Hash#has_key?` and `Hash#has_value?` will not be deprecated. Hence
rename the cop and corresponding messages to not use the word deprecated.
  • Loading branch information
tejasbubane authored and Neodelf committed Oct 15, 2016
1 parent 2adc0cb commit 52ccff6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

* [#3149](https://github.com/bbatsov/rubocop/pull/3149): Make `Style/HashSyntax` configurable to not report hash rocket syntax for symbols ending with ? or ! when using ruby19 style. ([@owst][])
* [#1758](https://github.com/bbatsov/rubocop/issues/1758): Let `Style/ClosingParenthesisIndentation` follow `Style/AlignParameters` configuration for method calls. ([@jonas054][])
* [#3224](https://github.com/bbatsov/rubocop/issues/3224): Rename `Style/DeprecatedHashMethods` to `Style/PreferredHashMethods`. ([@tejasbubane][])

## 0.40.0 (2016-05-09)

Expand Down
4 changes: 2 additions & 2 deletions config/enabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ Style/DefWithParentheses:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
Enabled: true

Style/DeprecatedHashMethods:
Description: 'Checks for use of deprecated Hash methods.'
Style/PreferredHashMethods:
Description: 'Checks use of `has_key?` and `has_value?` Hash methods.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
Enabled: true

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
require 'rubocop/cop/style/constant_name'
require 'rubocop/cop/style/copyright'
require 'rubocop/cop/style/def_with_parentheses'
require 'rubocop/cop/style/deprecated_hash_methods'
require 'rubocop/cop/style/preferred_hash_methods'
require 'rubocop/cop/style/documentation'
require 'rubocop/cop/style/dot_position'
require 'rubocop/cop/style/double_negation'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
module RuboCop
module Cop
module Style
# This cop checks for uses of the deprecated methods Hash#has_key?
# and Hash#has_value?
class DeprecatedHashMethods < Cop
MSG = '`Hash#%s` is deprecated in favor of `Hash#%s`.'.freeze
# This cop checks for uses of methods Hash#has_key? and Hash#has_value?
# Prefer to use Hash#key? and Hash#value? instead
class PreferredHashMethods < Cop
MSG = 'Use `Hash#%s` instead of `Hash#%s`.'.freeze

DEPRECATED_METHODS = [:has_key?, :has_value?].freeze
PREFERRED_METHODS = [:has_key?, :has_value?].freeze

def on_send(node)
_receiver, method_name, *args = *node
return unless args.size == 1 &&
DEPRECATED_METHODS.include?(method_name)
PREFERRED_METHODS.include?(method_name)

add_offense(node, :selector,
format(MSG,
method_name,
proper_method_name(method_name)))
proper_method_name(method_name),
method_name))
end

def autocorrect(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

require 'spec_helper'

describe RuboCop::Cop::Style::DeprecatedHashMethods do
describe RuboCop::Cop::Style::PreferredHashMethods do
subject(:cop) { described_class.new }

it 'registers an offense for has_key? with one arg' do
inspect_source(cop,
'o.has_key?(o)')
expect(cop.offenses.size).to eq(1)
expect(cop.messages)
.to eq(['`Hash#has_key?` is deprecated in favor of `Hash#key?`.'])
.to eq(['Use `Hash#key?` instead of `Hash#has_key?`.'])
end

it 'accepts has_key? with no args' do
Expand All @@ -25,7 +25,7 @@
'o.has_value?(o)')
expect(cop.offenses.size).to eq(1)
expect(cop.messages)
.to eq(['`Hash#has_value?` is deprecated in favor of `Hash#value?`.'])
.to eq(['Use `Hash#value?` instead of `Hash#has_value?`.'])
end

it 'accepts has_value? with no args' do
Expand Down

0 comments on commit 52ccff6

Please sign in to comment.