Class: RuboCop::Cop::RBS::Style::RedundantParentheses
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Style::RedundantParentheses
- Extended by:
- AutoCorrector
- Includes:
- BeforeTokenIfLparen
- Defined in:
- lib/rubocop/cop/rbs/style/redundant_parentheses.rb
Overview
Check for redundant parentheses.
Defined Under Namespace
Modules: BeforeTokenIfLparen Classes: ParenChecker
Instance Attribute Summary
Attributes inherited from RBS::CopBase
Instance Method Summary collapse
- #check_type(tokens:, type:, base:, skip: Set.new) ⇒ Object
- #on_rbs_constant(const) ⇒ Object (also: #on_rbs_global, #on_rbs_type_alias, #on_rbs_attribute, #on_rbs_var)
- #on_rbs_def(decl) ⇒ Object
Methods included from BeforeTokenIfLparen
Methods inherited from RBS::CopBase
documentation_url, #investigation_rbs, #location_to_range, #on_new_investigation, #on_other_file, #on_rbs_class, #on_rbs_interface, #on_rbs_module, #on_rbs_new_investigation, #on_rbs_parsing_error, #on_rbs_private, #on_rbs_public, #parse_rbs, #rbs_buffer, #tokenize, #walk
Methods included from RBS::OnTypeHelper
Instance Method Details
#check_type(tokens:, type:, base:, skip: Set.new) ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/rubocop/cop/rbs/style/redundant_parentheses.rb', line 142 def check_type(tokens:, type:, base:, skip: Set.new) ParenChecker.new( processed_source:, base:, tokens:, type:, skip:, cop: self ).check end |
#on_rbs_constant(const) ⇒ Object Also known as: on_rbs_global, on_rbs_type_alias, on_rbs_attribute, on_rbs_var
153 154 155 156 157 158 |
# File 'lib/rubocop/cop/rbs/style/redundant_parentheses.rb', line 153 def on_rbs_constant(const) tokens = tokenize(const.location.source) type = const.type base = const.location.start_pos check_type(tokens:, type:, base:) end |
#on_rbs_def(decl) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rubocop/cop/rbs/style/redundant_parentheses.rb', line 123 def on_rbs_def(decl) base = decl.location.start_pos tokens = tokenize(decl.location.source) skip = Set.new decl.overloads.each do |overload| before_token_if_lparen(tokens, base, overload.method_type.type) do |b| skip << (b.location.start_pos + base) end if overload.method_type.block before_token_if_lparen(tokens, base, overload.method_type.block.type) do |b| skip << (b.location.start_pos + base) end end overload.method_type.each_type do |type| check_type(tokens:, type:, base:, skip:) end end end |