Commit 9fa3267b authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement granular on/off switching of warnings.

Each warning is now signed a type, and using the new --warnings
option one can turn specific warnings on or off.  For example to
show only warnings about global members:

    --warnings=-all,+global
parent 4fad6ce1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -33,12 +33,12 @@ module JsDuck

      orig = @relations[al_def[:cls]]
      unless orig
        Logger.instance.warn("Class #{al_def[:cls]} not found", context[:filename], context[:linenr])
        Logger.instance.warn(:alias, "Class #{al_def[:cls]} not found", context[:filename], context[:linenr])
        return al
      end
      orig = orig.get_member(al_def[:member], al_def[:type] || al[:tagname])
      unless orig
        Logger.instance.warn("Member #{al_def[:cls]}##{al_def[:member]} not found", context[:filename], context[:linenr])
        Logger.instance.warn(:alias, "Member #{al_def[:cls]}##{al_def[:member]} not found", context[:filename], context[:linenr])
        return al
      end

+3 −4
Original line number Diff line number Diff line
@@ -33,9 +33,6 @@ module JsDuck
      # Sets the nr of parallel processes to use.
      # Set to 0 to disable parallelization completely.
      @parallel = ParallelWrap.new(:in_processes => @opts.processes)
      # Sets warnings and verbose mode on or off
      Logger.instance.warnings = @opts.warnings
      Logger.instance.verbose = @opts.verbose
      # Turn JSON pretty-printing on/off
      JsonDuck.pretty = @opts.pretty_json
    end
@@ -145,7 +142,9 @@ module JsDuck
          type = d[:tagname].to_s
          name = d[:name]
          file = d[:files][0]
          Logger.instance.warn("Ignoring #{type}: #{name}", file[:filename], file[:linenr])
          # This warning is shown when there are orphaned members,
          # but the creation of global class has been turned off.
          Logger.instance.warn(:global, "Ignoring #{type}: #{name}", file[:filename], file[:linenr])
        end
      end
      Relations.new(classes, @opts.external_classes)
+3 −3
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ module JsDuck

      # Don't crash if old syntax is used.
      if @categories.is_a?(Hash) && @categories["categories"]
        Logger.instance.warn('Update categories file to contain just the array inside {"categories": [...]}')
        Logger.instance.warn(:old_cat_format, 'Update categories file to contain just the array inside {"categories": [...]}')
        @categories = @categories["categories"]
      end

@@ -44,7 +44,7 @@ module JsDuck
      re = Regexp.new("^" + name.split(/\*/, -1).map {|part| Regexp.escape(part) }.join('.*') + "$")
      classes = @relations.to_a.find_all {|cls| re =~ cls[:name] && !cls[:private] }.map {|cls| cls[:name] }.sort
      if classes.length == 0
        Logger.instance.warn("No class found matching a pattern '#{name}' in categories file.")
        Logger.instance.warn(:cat_no_match, "No class found matching a pattern '#{name}' in categories file.")
      end
      classes
    end
@@ -64,7 +64,7 @@ module JsDuck
      # Check that each existing non-private class is listed
      @relations.each do |cls|
        unless listed_classes[cls[:name]] || cls[:private]
          Logger.instance.warn("Class '#{cls[:name]}' not found in categories file")
          Logger.instance.warn(:cat_class_missing, "Class '#{cls[:name]}' not found in categories file")
        end
      end
    end
+2 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ module JsDuck
        @relations[classname]
      elsif !@relations.ignore?(classname)
        context = @doc[:files][0]
        Logger.instance.warn("Class #{classname} not found", context[:filename], context[:linenr])
        Logger.instance.warn(:extend, "Class #{classname} not found", context[:filename], context[:linenr])
        nil
      end
    end
@@ -115,7 +115,7 @@ module JsDuck
      if @doc[:singleton] && context == :statics
        # Warn if singleton has static members
        if @doc[context][type].length > 0
          Logger.instance.warn("Singleton class #{@doc[:name]} can't have static members, remove the @static tag.")
          Logger.instance.warn(:sing_static, "Singleton class #{@doc[:name]} can't have static members, remove the @static tag.")
        end
        return {}
      end
+2 −2
Original line number Diff line number Diff line
@@ -69,9 +69,9 @@ module JsDuck
      else
        context = @formatter.doc_context
        if tp.error == :syntax
          Logger.instance.warn("Incorrect type syntax #{type}", context[:filename], context[:linenr])
          Logger.instance.warn(:type_syntax, "Incorrect type syntax #{type}", context[:filename], context[:linenr])
        else
          Logger.instance.warn("Unknown type #{type}", context[:filename], context[:linenr])
          Logger.instance.warn(:type_name, "Unknown type #{type}", context[:filename], context[:linenr])
        end
        type
      end
Loading