Sha256: 9067f1473fe2706f01ad6d4693eb72923a67a5dfabb508dc3e3084ed564e76b3

Contents?: true

Size: 1022 Bytes

Versions: 18

Compression:

Stored size: 1022 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

18 entries across 18 versions & 1 rubygems

Version Path
rbi-0.2.1 lib/rbi/rewriters/deannotate.rb
rbi-0.2.0 lib/rbi/rewriters/deannotate.rb
rbi-0.1.14 lib/rbi/rewriters/deannotate.rb
rbi-0.1.13 lib/rbi/rewriters/deannotate.rb
rbi-0.1.12 lib/rbi/rewriters/deannotate.rb
rbi-0.1.11 lib/rbi/rewriters/deannotate.rb
rbi-0.1.10 lib/rbi/rewriters/deannotate.rb
rbi-0.1.9 lib/rbi/rewriters/deannotate.rb
rbi-0.1.8 lib/rbi/rewriters/deannotate.rb
rbi-0.1.7 lib/rbi/rewriters/deannotate.rb
rbi-0.1.6 lib/rbi/rewriters/deannotate.rb
rbi-0.1.5 lib/rbi/rewriters/deannotate.rb
rbi-0.1.4 lib/rbi/rewriters/deannotate.rb
rbi-0.1.3 lib/rbi/rewriters/deannotate.rb
rbi-0.1.2 lib/rbi/rewriters/deannotate.rb
rbi-0.1.1 lib/rbi/rewriters/deannotate.rb
rbi-0.1.0 lib/rbi/rewriters/deannotate.rb
rbi-0.0.17 lib/rbi/rewriters/deannotate.rb