Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot unset default InverseMethods in Style/InverseMethods #6926

Closed
dduugg opened this issue Apr 12, 2019 · 0 comments · Fixed by #6942
Closed

Cannot unset default InverseMethods in Style/InverseMethods #6926

dduugg opened this issue Apr 12, 2019 · 0 comments · Fixed by #6942

Comments

@dduugg
Copy link
Contributor

dduugg commented Apr 12, 2019

The default setting of Style/InverseMethods includes:

Style/InverseMethods:
  InverseMethods:
    :any?: :none?
    :even?: :odd?
    :==: :!=
    :=~: :!~
    :<: :>=
    :>: :<=

I would like to unset the :< and :> entries, as the inverse methods are not correct when comparing classes, e.g.

!(Integer < String)

is not equivalent to

Integer >= String

In reading #4289 as well as https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md#inheritance-of-hashes-vs-other-types my understanding is that i should be able to unset them with:

Style/InverseMethods:
  InverseMethods:
    :<: ~
    :>: ~

Expected behavior

I would expect the above to result in (via rubocop --show-cops):

Style/InverseMethods:
  InverseMethods:
    :any?: :none?
    :even?: :odd?
    :==: :!=
    :=~: :!~

Actual behavior

Instead the result is:

Style/InverseMethods:
  InverseMethods:
    :any?: :none?
    :even?: :odd?
    :==: :!=
    :=~: :!~
    :<:
    :>:

This will continue to erroneously flag code such as !(a < b) (which, in addition, is autocorrected to a b).

Steps to reproduce the problem

I have written a failing test to capture the desired behavior:

context 'when a file inherits and overrides a hash with nil' do
  let(:file_path) { '.rubocop.yml' }

  before do
    create_file('.rubocop_parent.yml', <<-YAML.strip_indent)
      Style/InverseMethods:
        InverseMethods:
          :any?: :none?
          :even?: :odd?
          :==: :!=
          :=~: :!~
          :<: :>=
          :>: :<=
    YAML

    create_file('.rubocop.yml', <<-YAML.strip_indent)
      inherit_from: .rubocop_parent.yml

      Style/InverseMethods:
        InverseMethods:
          :<: ~
          :>: ~
          :foo: :bar
    YAML
  end

  it 'removes hash keys with nil values' do
    inverse_methods =
      configuration_from_file['Style/InverseMethods']['InverseMethods']
    expect(inverse_methods).to eq(
      '==': :!=,
      '=~': :!~,
      any?: :none?,
      even?: :odd?,
      foo: :bar
    )
  end
end

RuboCop version

0.67.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant