Commit 84cc4429 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Don't print warning message for all String @enums.

Only when the enum is an auto-expanded list of alias values
or when it's defined as array - only then show the warning.
parent bb3eede4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -274,6 +274,11 @@ module JsDuck
    # Detects class members from array literal
    def detect_class_members_from_array(cls, ast)
      cls[:members] = []

      # This will most likely be an @enum class, in which case the
      # enum will be for documentation purposes only.
      cls[:enum] = {:doc_only => true}

      ast["elements"].each do |el|
        detect_method_or_property(cls, key_value(el), el, el)
      end
@@ -484,4 +489,3 @@ module JsDuck
  end

end
+4 −1
Original line number Diff line number Diff line
@@ -280,9 +280,12 @@ module JsDuck
    def detect_enum(doc_map)
      return nil unless extract(doc_map, :class, :enum)

      default = extract(doc_map, :class, :default)

      return {
        :type => extract(doc_map, :class, :type),
        :default => extract(doc_map, :class, :default),
        :default => default,
        :doc_only => !!default,
      }
    end

+10 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ module JsDuck
      # Used by Aggregator to determine if we're dealing with Ext4 code
      h[:code_type] = code[:code_type] if code[:code_type]

      h[:enum] = merge_enum(docs, code) if docs[:enum]

      h[:members] = []

      h
@@ -163,6 +165,14 @@ module JsDuck
      return docs[:name] == nil || docs[:name] == code[:name]
    end

    # Takes the :enum always from docs, but the :doc_only can come
    # from either code or docs.
    def merge_enum(docs, code)
      enum = docs[:enum]
      enum[:doc_only] = docs[:enum][:doc_only] || (code[:enum] && code[:enum][:doc_only])
      enum
    end

  end

end
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ module JsDuck
    def render_enum_class_notice
      return if !@cls[:enum]

      if @cls[:enum][:type] == "String"
      if @cls[:enum][:doc_only]
        first = @cls[:members][:property][0] || {:name => 'foo', :default => '"foo"'}
        [
          "<p class='enum'><strong>ENUM:</strong> ",
+28 −4
Original line number Diff line number Diff line
@@ -47,6 +47,18 @@ describe JsDuck::Aggregator do
    end
  end

  shared_examples_for "doc_enum" do
    it "detects enum as only for documentation purposes" do
      doc[:enum][:doc_only].should == true
    end
  end

  shared_examples_for "non_doc_enum" do
    it "doesn't detect an enum for doc purposes only" do
      doc[:enum][:doc_only].should_not == true
    end
  end

  describe "explicit enum" do
    let(:doc) do
      parse(<<-EOS)[0]
@@ -60,6 +72,7 @@ describe JsDuck::Aggregator do
    end

    it_should_behave_like "enum"
    it_should_behave_like "non_doc_enum"
  end

  describe "implicitly named enum" do
@@ -79,6 +92,7 @@ describe JsDuck::Aggregator do
    end

    it_should_behave_like "enum"
    it_should_behave_like "non_doc_enum"
  end

  describe "enum with implicit values" do
@@ -175,8 +189,8 @@ describe JsDuck::Aggregator do
  end

  describe "enum with array value" do
    let(:members) do
      parse(<<-EOS)[0][:members]
    let(:doc) do
      parse(<<-EOS)[0]
        /** @enum */
        My.enum.Type = [
            "foo",
@@ -185,6 +199,10 @@ describe JsDuck::Aggregator do
      EOS
    end

    let(:members) { doc[:members] }

    it_should_behave_like "doc_enum"

    it "detects all members" do
      members.length.should == 2
    end
@@ -207,8 +225,8 @@ describe JsDuck::Aggregator do
  end

  describe "enum with documented array values" do
    let(:members) do
      parse(<<-EOS)[0][:members]
    let(:doc) do
      parse(<<-EOS)[0]
        /** @enum */
        My.enum.Smartness = [
            // A wise choice.
@@ -219,6 +237,10 @@ describe JsDuck::Aggregator do
      EOS
    end

    let(:members) { doc[:members] }

    it_should_behave_like "doc_enum"

    it "detects docs of first member" do
      members[0][:doc].should == 'A wise choice.'
    end
@@ -242,6 +264,8 @@ describe JsDuck::Aggregator do
      doc[:enum][:type].should == "String"
    end

    it_should_behave_like "doc_enum"

    let(:members) { doc[:members] }

    it "gathers all 3 widget.* aliases" do