Commit 87856f21 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move warning logging back to Doc::Subproperties.

Gets rid of all the duplicated warning logging code from the Tag classes
that use Doc::Subproperties.
parent c4559313
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
require 'jsduck/util/singleton'
require 'jsduck/logger'

module JsDuck
  module Doc
@@ -22,13 +23,12 @@ module JsDuck
      #         {:name => "baz"}]},
      #     {:name => "zap"},
      #
      # NOTE: It returns two values: the resulting nested items array
      # and warnings array of :subproperty warnings that should get
      # printed out.
      def nest(raw_items)
      # Secondly it takes a position argument which is used for
      # logging warnings when bogus subproperty syntax is encountered.
      def nest(raw_items, pos)
        # First item can't be namespaced, if it is ignore the rest.
        if raw_items[0] && raw_items[0][:name] =~ /\./
          return [raw_items[0]], []
          return [raw_items[0]]
        end

        # build name-index of all items
@@ -39,7 +39,6 @@ module JsDuck
        # Otherwise look up the parent of item and add it as the
        # property of that parent.
        items = []
        warnings = []
        raw_items.each do |it|
          if it[:name] =~ /^(.+)\.([^.]+)$/
            it[:name] = $2
@@ -48,14 +47,15 @@ module JsDuck
              parent[:properties] = [] unless parent[:properties]
              parent[:properties] << it
            else
              warnings << "Ignoring subproperty #{$1}.#{$2}, no parent found with name '#{$1}'."
              msg = "Ignoring subproperty #{$1}.#{$2}, no parent found with name '#{$1}'."
              Logger.warn(:subproperty, msg, pos[:filename], pos[:linenr])
            end
          else
            items << it
          end
        end

        return items, warnings
        return items
      end

    end
+1 −7
Original line number Diff line number Diff line
@@ -26,14 +26,8 @@ module JsDuck::Tag
      h[:name] = p[:name]
      h[:type] = p[:type]
      h[:default] = p[:default]
      h[:properties] = nest_properties(tags, pos)
      h[:properties] = JsDuck::Doc::Subproperties.nest(tags, pos)[0][:properties]
      h[:required] = true if p[:optional] == false
    end

    def nest_properties(tags, pos)
      items, warnings = JsDuck::Doc::Subproperties.nest(tags)
      warnings.each {|msg| JsDuck::Logger.warn(:subproperty, msg, pos[:filename], pos[:linenr]) }
      items[0][:properties]
    end
  end
end
+1 −3
Original line number Diff line number Diff line
@@ -21,9 +21,7 @@ module JsDuck::Tag
    end

    def process_doc(h, tags, pos)
      items, warnings = JsDuck::Doc::Subproperties.nest(tags)
      warnings.each {|msg| JsDuck::Logger.warn(:subproperty, msg, pos[:filename], pos[:linenr]) }
      h[:params] = items
      h[:params] = JsDuck::Doc::Subproperties.nest(tags, pos)
    end
  end
end
+1 −7
Original line number Diff line number Diff line
@@ -22,13 +22,7 @@ module JsDuck::Tag
      # Type might also come from @type, don't overwrite it with nil.
      h[:type] = p[:type] if p[:type]
      h[:default] = p[:default]
      h[:properties] = nest_properties(tags, pos)
    end

    def nest_properties(tags, pos)
      items, warnings = JsDuck::Doc::Subproperties.nest(tags)
      warnings.each {|msg| JsDuck::Logger.warn(:subproperty, msg, pos[:filename], pos[:linenr]) }
      items[0][:properties]
      h[:properties] = JsDuck::Doc::Subproperties.nest(tags, pos)[0][:properties]
    end
  end
end
+1 −7
Original line number Diff line number Diff line
@@ -30,14 +30,8 @@ module JsDuck::Tag
        :type => ret[:type] || "Object",
        :name => ret[:name] || "return",
        :doc => ret[:doc] || "",
        :properties => nest_properties(tags, pos)[0][:properties]
        :properties => JsDuck::Doc::Subproperties.nest(tags, pos)[0][:properties],
      }
    end

    def nest_properties(tags, pos)
      items, warnings = JsDuck::Doc::Subproperties.nest(tags)
      warnings.each {|msg| JsDuck::Logger.warn(:subproperty, msg, pos[:filename], pos[:linenr]) }
      items
    end
  end
end