-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR resolves the fundamental issue mentioned in rubocop/rubocop#13051. Although rational literal (e.g., `(0.2r)` is a basic literal that return `true` for `RuboCop::AST::Node#numeric_type?` and `RuboCop::AST::Node#literal?`, their behavior was not sufficiently covered as a `NumericNode`. This PR maps rational literal to `RationalNode` to enable expected node operations for rational literals.
- Loading branch information
Showing
7 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#304](https://github.com/rubocop/rubocop-ast/pull/304): Add `RuboCop::AST::RationalNode`. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module AST | ||
# A node extension for `rational` nodes. This will be used in place of a plain | ||
# node when the builder constructs the AST, making its methods available to | ||
# all `rational` nodes within RuboCop. | ||
class RationalNode < Node | ||
include BasicLiteralNode | ||
include NumericNode | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::AST::RationalNode do | ||
subject(:rational_node) { parse_source(source).ast } | ||
|
||
describe '.new' do | ||
let(:source) { '0.2r' } | ||
|
||
it { is_expected.to be_a(described_class) } | ||
end | ||
|
||
describe '#sign?' do | ||
context 'when explicit positive rational' do | ||
let(:source) { '+0.2r' } | ||
|
||
it { is_expected.to be_sign } | ||
end | ||
|
||
context 'when explicit negative rational' do | ||
let(:source) { '-0.2r' } | ||
|
||
it { is_expected.to be_sign } | ||
end | ||
end | ||
|
||
describe '#value' do | ||
let(:source) do | ||
'0.4r' | ||
end | ||
|
||
it { expect(rational_node.value).to eq(0.4r) } | ||
end | ||
end |