Commit 228b52e8 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Warn about duplicate assets only within a group.

It's now OK for a guide to be listed in multiple groupes, but when
it's listed multiple times within one group, a warning is printed.

Also added new warning type :dup_asset.
parent 5209c4f4
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -10,13 +10,20 @@ module JsDuck
  class GroupedAsset
    # Should be called from constructor after @groups have been read in,
    # and after it's been ensured that all items in groupes have names.
    #
    # Prints warning when there is a duplicate item within a group.
    # The warning message should say something like "duplicate <asset type>"
    def build_map_by_name(warning_msg)
      @map_by_name = {}
      each_item do |item|
        if @map_by_name[item["name"]]
          Logger.instance.warn(nil, "#{warning_msg} '#{item['name']}'")
      @groups.each do |group|
        group_map = {}
        group["items"].each do |item|
          if group_map[item["name"]]
            Logger.instance.warn(:dup_asset, "#{warning_msg} '#{item['name']}'")
          end
          @map_by_name[item["name"]] = item
          group_map[item["name"]] = item
        end
      end
    end

+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ module JsDuck
        [:no_doc, "Member or class without documentation"],
        [:dup_param, "Method has two parameters with the same name"],
        [:dup_member, "Class has two members with the same name"],
        [:dup_asset, "Duplicate guide/video/example"],
        [:req_after_opt, "Required parameter comes after optional"],
        [:subproperty, "@param foo.bar where foo param doesn't exist"],
        [:sing_static, "Singleton class member marked as @static"],