Sha256: 5391ebce005215f15f133a44f14ab33f0c85431e873804d7ceeff518683f76c1

Contents?: true

Size: 1021 Bytes

Versions: 11

Compression:

Stored size: 1021 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module RBI
  module Rewriters
    class Deannotate < Visitor
      extend T::Sig

      sig { params(annotation: String).void }
      def initialize(annotation)
        super()
        @annotation = annotation
      end

      sig { override.params(node: T.nilable(Node)).void }
      def visit(node)
        case node
        when Scope, Const, Attr, Method, TStructField, TypeMember
          deannotate_node(node)
        end
        visit_all(node.nodes) if node.is_a?(Tree)
      end

      private

      sig { params(node: NodeWithComments).void }
      def deannotate_node(node)
        return unless node.annotations.one?(@annotation)
        node.comments.reject! do |comment|
          comment.text == "@#{@annotation}"
        end
      end
    end
  end

  class Tree
    extend T::Sig

    sig { params(annotation: String).void }
    def deannotate!(annotation)
      visitor = Rewriters::Deannotate.new(annotation)
      visitor.visit(self)
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/rbi-0.0.16/lib/rbi/rewriters/deannotate.rb
rbi-0.0.16 lib/rbi/rewriters/deannotate.rb
rbi-0.0.15 lib/rbi/rewriters/deannotate.rb
rbi-0.0.14 lib/rbi/rewriters/deannotate.rb
rbi-0.0.13 lib/rbi/rewriters/deannotate.rb
rbi-0.0.12 lib/rbi/rewriters/deannotate.rb
rbi-0.0.11 lib/rbi/rewriters/deannotate.rb
rbi-0.0.10 lib/rbi/rewriters/deannotate.rb
rbi-0.0.9 lib/rbi/rewriters/deannotate.rb
rbi-0.0.8 lib/rbi/rewriters/deannotate.rb
rbi-0.0.7 lib/rbi/rewriters/deannotate.rb