diff --git a/changelog/fix_numeric_node_sign_to_return_boolean.md b/changelog/fix_numeric_node_sign_to_return_boolean.md new file mode 100644 index 000000000..7f6ee39b2 --- /dev/null +++ b/changelog/fix_numeric_node_sign_to_return_boolean.md @@ -0,0 +1 @@ +* [#380](https://github.com/rubocop/rubocop-ast/pull/380): Fix `RuboCop::AST::NumericNode#sign?` to return boolean. ([@viralpraxis][]) diff --git a/lib/rubocop/ast/node/mixin/numeric_node.rb b/lib/rubocop/ast/node/mixin/numeric_node.rb index 69e7ab146..66e0dd51a 100644 --- a/lib/rubocop/ast/node/mixin/numeric_node.rb +++ b/lib/rubocop/ast/node/mixin/numeric_node.rb @@ -15,7 +15,7 @@ module NumericNode # # @return [Boolean] whether this literal has a sign. def sign? - source.match(SIGN_REGEX) + source.match?(SIGN_REGEX) end end end diff --git a/spec/rubocop/ast/float_node_spec.rb b/spec/rubocop/ast/float_node_spec.rb index 8f2803313..b4fe5491f 100644 --- a/spec/rubocop/ast/float_node_spec.rb +++ b/spec/rubocop/ast/float_node_spec.rb @@ -10,16 +10,18 @@ end describe '#sign?' do + subject { float_node.sign? } + context 'explicit positive float' do let(:source) { '+42.0' } - it { is_expected.to be_sign } + it { is_expected.to be(true) } end context 'explicit negative float' do let(:source) { '-42.0' } - it { is_expected.to be_sign } + it { is_expected.to be(true) } end end diff --git a/spec/rubocop/ast/int_node_spec.rb b/spec/rubocop/ast/int_node_spec.rb index 677e7109b..47d1bfd10 100644 --- a/spec/rubocop/ast/int_node_spec.rb +++ b/spec/rubocop/ast/int_node_spec.rb @@ -10,16 +10,18 @@ end describe '#sign?' do + subject { int_node.sign? } + context 'explicit positive int' do let(:source) { '+42' } - it { is_expected.to be_sign } + it { is_expected.to be(true) } end context 'explicit negative int' do let(:source) { '-42' } - it { is_expected.to be_sign } + it { is_expected.to be(true) } end end diff --git a/spec/rubocop/ast/rational_node_spec.rb b/spec/rubocop/ast/rational_node_spec.rb index 8e27da8e8..a253ce395 100644 --- a/spec/rubocop/ast/rational_node_spec.rb +++ b/spec/rubocop/ast/rational_node_spec.rb @@ -10,16 +10,18 @@ end describe '#sign?' do + subject { rational_node.sign? } + context 'when explicit positive rational' do let(:source) { '+0.2r' } - it { is_expected.to be_sign } + it { is_expected.to be(true) } end context 'when explicit negative rational' do let(:source) { '-0.2r' } - it { is_expected.to be_sign } + it { is_expected.to be(true) } end end