Class: RuboCop::Cop::RBS::Lint::NewReturnsVoid
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Lint::NewReturnsVoid
- Defined in:
- lib/rubocop/cop/rbs/lint/new_returns_void.rb
Overview
Checks that there are void types in the return type of ‘.new` method `self.new` is a special and fundamental method, and extra care should be taken regarding its return value. In most cases, assigning it `void` is an unintended mistake.
Constant Summary collapse
- MSG =
"Don't use `void` in self.new method. Did you mean `instance`?"
Instance Attribute Summary
Attributes inherited from RBS::CopBase
Instance Method Summary collapse
Methods inherited from RBS::CopBase
documentation_url, #investigation_rbs, #location_to_range, #on_new_investigation, #on_other_file, #on_rbs_attribute, #on_rbs_class, #on_rbs_constant, #on_rbs_global, #on_rbs_interface, #on_rbs_module, #on_rbs_new_investigation, #on_rbs_parsing_error, #on_rbs_private, #on_rbs_public, #on_rbs_type_alias, #on_rbs_var, #parse_rbs, #rbs_buffer, #tokenize, #walk
Methods included from RBS::OnTypeHelper
Instance Method Details
#on_rbs_def(decl) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/rbs/lint/new_returns_void.rb', line 24 def on_rbs_def(decl) return unless decl.kind == :singleton return unless decl.name == :new decl.overloads.each do |overload| return_type = overload.method_type.type.return_type case return_type when ::RBS::Types::Bases::Void next unless return_type.location range = location_to_range(return_type.location) add_offense(range) end end end |