Skip to content

Commit dd235ed

Browse files
viralpraxiskoic
andcommitted
Fix RuboCop::AST::NumericNode#sign? to return boolean
The documentation states that `sign?` returns boolean: ```ruby def sign? source.match(SIGN_REGEX) end ``` but it does not. Looks like the only usage [1] of `sign?` is this [2] module, so nothing should break. [1] https://github.com/search?q=org%3Arubocop%20sign%3F&type=code [2] https://github.com/rubocop/rubocop/blob/ddbb2a1bb65a29ac2d2d963196f7b00821779fd6/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb#L226 Co-authored-by: Koichi ITO <[email protected]>
1 parent 4c51ecd commit dd235ed

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#380](https://github.com/rubocop/rubocop-ast/pull/380): Fix `RuboCop::AST::NumericNode#sign?` to return boolean. ([@viralpraxis][])

lib/rubocop/ast/node/mixin/numeric_node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module NumericNode
1515
#
1616
# @return [Boolean] whether this literal has a sign.
1717
def sign?
18-
source.match(SIGN_REGEX)
18+
source.match?(SIGN_REGEX)
1919
end
2020
end
2121
end

spec/rubocop/ast/float_node_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
end
1111

1212
describe '#sign?' do
13+
subject { float_node.sign? }
14+
1315
context 'explicit positive float' do
1416
let(:source) { '+42.0' }
1517

16-
it { is_expected.to be_sign }
18+
it { is_expected.to be(true) }
1719
end
1820

1921
context 'explicit negative float' do
2022
let(:source) { '-42.0' }
2123

22-
it { is_expected.to be_sign }
24+
it { is_expected.to be(true) }
2325
end
2426
end
2527

spec/rubocop/ast/int_node_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
end
1111

1212
describe '#sign?' do
13+
subject { int_node.sign? }
14+
1315
context 'explicit positive int' do
1416
let(:source) { '+42' }
1517

16-
it { is_expected.to be_sign }
18+
it { is_expected.to be(true) }
1719
end
1820

1921
context 'explicit negative int' do
2022
let(:source) { '-42' }
2123

22-
it { is_expected.to be_sign }
24+
it { is_expected.to be(true) }
2325
end
2426
end
2527

spec/rubocop/ast/rational_node_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
end
1111

1212
describe '#sign?' do
13+
subject { rational_node.sign? }
14+
1315
context 'when explicit positive rational' do
1416
let(:source) { '+0.2r' }
1517

16-
it { is_expected.to be_sign }
18+
it { is_expected.to be(true) }
1719
end
1820

1921
context 'when explicit negative rational' do
2022
let(:source) { '-0.2r' }
2123

22-
it { is_expected.to be_sign }
24+
it { is_expected.to be(true) }
2325
end
2426
end
2527

0 commit comments

Comments
 (0)