Fix Style/MethodCallWithArgsParentheses cop error on complex numbers#14146
Merged
koic merged 1 commit intoMay 2, 2025
Conversation
`EnforcedStyle: omit_parentheses`
```bash
undefined method `sign?' for an instance of RuboCop::AST::Node
# ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:226:in `unary_literal?'
# ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:201:in `ambiguous_literal?'
# ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:146:in `block in call_with_ambiguous_arguments?'
```
koic
added a commit
to koic/rubocop-ast
that referenced
this pull request
May 2, 2025
This PR supports `RuboCop::AST::ComplexNode`. The `complex` type is categorized as a `numeric` type, so it should be handled transparently alongside `int`, `float`, and `rational`. ```ruby int: :numeric, float: :numeric, rational: :numeric, complex: :numeric, ``` https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109 This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
Member
|
It's likely that the implementation condition can be reverted in the future with rubocop/rubocop-ast#379, but this looks like a reasonable workaround for now. |
viralpraxis
added a commit
to viralpraxis/rubocop
that referenced
this pull request
May 3, 2025
For some reason I didn't check that signless complex numbers work well with this cop. In that case `(node.complex_type? && node.source.match?(/\A[+-]/))` would be `false` and we'd still try to send non-existend `sign?` message.
viralpraxis
deleted the
fix-style-method-call-with-args-parentheses-with-complex-numbers
branch
May 4, 2025 18:48
bbatsov
pushed a commit
that referenced
this pull request
May 4, 2025
For some reason I didn't check that signless complex numbers work well with this cop. In that case `(node.complex_type? && node.source.match?(/\A[+-]/))` would be `false` and we'd still try to send non-existend `sign?` message.
koic
added a commit
to koic/rubocop-ast
that referenced
this pull request
Jul 16, 2025
This PR supports `RuboCop::AST::ComplexNode`. The `complex` type is categorized as a `numeric` type, so it should be handled transparently alongside `int`, `float`, and `rational`. ```ruby int: :numeric, float: :numeric, rational: :numeric, complex: :numeric, ``` https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109 This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
koic
added a commit
to koic/rubocop-ast
that referenced
this pull request
Jul 16, 2025
This PR supports `RuboCop::AST::ComplexNode`. The `complex` type is categorized as a `numeric` type, so it should be handled transparently alongside `int`, `float`, and `rational`. ```ruby int: :numeric, float: :numeric, rational: :numeric, complex: :numeric, ``` https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109 This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
marcandre
pushed a commit
to rubocop/rubocop-ast
that referenced
this pull request
Jul 16, 2025
This PR supports `RuboCop::AST::ComplexNode`. The `complex` type is categorized as a `numeric` type, so it should be handled transparently alongside `int`, `float`, and `rational`. ```ruby int: :numeric, float: :numeric, rational: :numeric, complex: :numeric, ``` https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109 This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EnforcedStyle: omit_parenthesesBefore submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.