Sha256: 790ec3529ea160b0aef2a9ad37188258d769467dae346ff8d557417645b61347
Contents?: true
Size: 1.51 KB
Versions: 3
Compression:
Stored size: 1.51 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RBS module Lint # Notice useless overload type parameters. # # @example default # # bad # def foo: [T] () -> void # # # good # def foo: [T] (T) -> T class UselessOverloadTypeParams < RuboCop::RBS::CopBase MSG = 'Useless overload type variable - `%<variable>s`.' def on_rbs_def(decl) decl.overloads.each do |overload| next if overload.method_type.type_params.empty? type_params = overload.method_type.type_params.dup overload.method_type.each_type do |type| used_variable_in_type(type) do |var| type_params.delete_if { |type_param| type_param.name == var.name } end end next if type_params.empty? type_params.each do |type_param| next unless type_param.location t = location_to_range(type_param.location[:name]) add_offense(t, message: format(MSG, variable: type_param.name), severity: :warning) end end end def used_variable_in_type(type, &block) case type when ::RBS::Types::Variable yield type else type.each_type do |t| used_variable_in_type(t, &block) end end end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems