Class: RuboCop::Cop::RBS::Lint::UselessAccessModifier
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Lint::UselessAccessModifier
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rbs/lint/useless_access_modifier.rb
Overview
Checks for redundant access modifiers in class and module definitions.
Constant Summary collapse
- MSG =
'Useless `%<current>s` access modifier.'
Instance Attribute Summary
Attributes inherited from RBS::CopBase
Instance Method Summary collapse
- #autocorrect(corrector, range) ⇒ Object
- #on_rbs_class(decl) ⇒ Object (also: #on_rbs_module)
Methods inherited from RBS::CopBase
documentation_url, #investigation_rbs, #location_to_range, #on_new_investigation, #on_other_file, #on_rbs_attribute, #on_rbs_constant, #on_rbs_def, #on_rbs_global, #on_rbs_interface, #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
#autocorrect(corrector, range) ⇒ Object
89 90 91 92 |
# File 'lib/rubocop/cop/rbs/lint/useless_access_modifier.rb', line 89 def autocorrect(corrector, range) line = range_by_whole_lines(range, include_final_newline: true) corrector.remove(line) end |
#on_rbs_class(decl) ⇒ Object Also known as: on_rbs_module
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rubocop/cop/rbs/lint/useless_access_modifier.rb', line 44 def on_rbs_class(decl) current = nil unused = true decl.members.each do |member| next unless member.location case member when ::RBS::AST::Members::Public if current.nil? || current.is_a?(::RBS::AST::Members::Public) range = location_to_range(member.location) add_offense(range, message: format(MSG, { current: 'public' })) do |corrector| autocorrect(corrector, range) end end current = member when ::RBS::AST::Members::Private if current.is_a?(::RBS::AST::Members::Private) range = location_to_range(member.location) add_offense(range, message: format(MSG, { current: 'private' })) do |corrector| autocorrect(corrector, range) end end current = member when ::RBS::AST::Members::MethodDefinition if member.kind != :singleton unused = false end end end if unused && current range = location_to_range(current.location) vis = case current when ::RBS::AST::Members::Public 'public' when ::RBS::AST::Members::Private 'private' end add_offense(range, message: format(MSG, { current: vis })) do |corrector| autocorrect(corrector, range) end end end |