Commit 832057f7 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Improve warnings for bogus subproperty syntax.

Also print a warning when the first and only property uses
namespaced subproperty syntax.

Additionally truncate the name of the first property to
remove anything after the dot.

So that when somebody writes:

  /** @cfg foo.bar */

We print a warning and treat it as if he had written:

  /** @cfg foo */

Fixes: #341
parent 8c4d7497
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ module JsDuck
      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] =~ /\./
          warn(raw_items[0][:name], pos)
          raw_items[0][:name].sub!(/\..*$/, '')
          return [raw_items[0]]
        end

@@ -47,8 +49,7 @@ module JsDuck
              parent[:properties] = [] unless parent[:properties]
              parent[:properties] << it
            else
              msg = "Ignoring subproperty #{$1}.#{$2}, no parent found with name '#{$1}'."
              Logger.warn(:subproperty, msg, pos)
              warn("#{$1}.#{$2}", pos)
            end
          else
            items << it
@@ -58,6 +59,12 @@ module JsDuck
        return items
      end

      def warn(name, pos)
        parent = name.sub(/\.[^.]*$/, '')
        msg = "Ignoring subproperty '#{name}' not parent found with name '#{parent}'."
        Logger.warn(:subproperty, msg, pos)
      end

    end

  end
+5 −2
Original line number Diff line number Diff line
@@ -34,13 +34,16 @@ module JsDuck::Tag

    def process_doc(h, tags, pos)
      p = tags[0]
      h[:name] = p[:name]
      h[:type] = p[:type]
      h[:default] = p[:default]
      h[:properties] = JsDuck::Doc::Subproperties.nest(tags, pos)[0][:properties]
      h[:required] = true if p[:optional] == false

      # Documentation after the first @cfg is part of the top-level docs.
      h[:doc] += p[:doc]

      nested = JsDuck::Doc::Subproperties.nest(tags, pos)[0]
      h[:properties] = nested[:properties]
      h[:name] = nested[:name]
    end
  end
end
+5 −2
Original line number Diff line number Diff line
@@ -28,13 +28,16 @@ module JsDuck::Tag

    def process_doc(h, tags, pos)
      p = tags[0]
      h[:name] = p[:name]
      # 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] = JsDuck::Doc::Subproperties.nest(tags, pos)[0][:properties]

      # Documentation after the first @property is part of the top-level docs.
      h[:doc] += p[:doc]

      nested = JsDuck::Doc::Subproperties.nest(tags, pos)[0]
      h[:properties] = nested[:properties]
      h[:name] = nested[:name]
    end
  end
end