Commit bb00b2ec authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Added --external command line option.

Allows to avoid warnings when extending classes for which we don't
have source code.  For example in ExtJS it's useful to specify
--external=Error, because Ext.Error extends the built-in Error
object.
parent 4c9dc437
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -73,6 +73,13 @@ opts = OptionParser.new do | opts |
    app.ignore_global = true
  end

  opts.on('--external=CLASSNAME', "Declare an external class.",
    "When declared as external, inheriting from this class will not",
    "trigger warnings.  Useful when you are extending a class for which",
    "you can not supply source code.") do |classname|
    app.external_classes << classname
  end

  opts.on('-v', '--verbose', "This will fill up your console.") do
    app.verbose = true
  end
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ module JsDuck
    attr_accessor :link_tpl
    attr_accessor :img_tpl
    attr_accessor :ignore_global
    attr_accessor :external_classes

    def initialize
      @output_dir = nil
@@ -39,6 +40,7 @@ module JsDuck
      @link_tpl = nil
      @img_tpl = nil
      @ignore_global = false
      @external_classes = []
      @timer = Timer.new
      @parallel = ParallelWrap.new
    end
@@ -113,7 +115,7 @@ module JsDuck
          puts "Warning: Ignoring #{type}: #{name} in #{file} line #{line}"
        end
      end
      Relations.new(classes)
      Relations.new(classes, @external_classes)
    end

    # print warning for each global member
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ module JsDuck
    def lookup(classname)
      if @relations[classname]
        @relations[classname]
      elsif classname != "Object"
      elsif !@relations.ignore?(classname)
        puts "Warning: Class #{classname} not found in #{@doc[:filename]} line #{@doc[:linenr]}"
      end
    end
+11 −3
Original line number Diff line number Diff line
@@ -4,14 +4,17 @@ module JsDuck
  #
  # Also provides a place to look up classes by name.
  #
  # The constructor is initialized with array of all available
  # classes.
  # The constructor is initialized with array of all available classes
  # and list of class names to ignore.  By default the latter list
  # contains only JavaScript base class "Object".
  class Relations
    # Returns list of all classes
    attr_reader :classes

    def initialize(classes = [])
    def initialize(classes = [], ignorables = [])
      @classes = classes
      @ignorables = {"Object" => true}
      ignorables.each {|classname| @ignorables[classname] = true }

      # First build class lookup table; building lookup tables for
      # mixins and subclasses will depend on that.
@@ -34,6 +37,11 @@ module JsDuck
      @lookup[classname]
    end

    # Returns true if class is in list of ignored classes.
    def ignore?(classname)
      @ignorables[classname]
    end

    def each(&block)
      @classes.each(&block)
    end