Loading lib/jsduck/doc/parser.rb +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ module JsDuck skip_white else warn(:tag, "Unsupported tag: @#{name}") warn(:tag, "Unsupported tag: @#{name}", [name.to_sym]) @multiline_tag[:doc] += "@" end end Loading lib/jsduck/doc/scanner.rb +2 −2 Original line number Diff line number Diff line Loading @@ -73,8 +73,8 @@ module JsDuck end # Prints a warning message def warn(type, msg) Logger.warn(type, msg, @position) def warn(type, msg, params=[]) Logger.warn(type, msg, @position, params) end end Loading lib/jsduck/warning/registry.rb +4 −1 Original line number Diff line number Diff line require 'jsduck/warning/basic' require 'jsduck/warning/nodoc' require 'jsduck/warning/tag' require 'jsduck/warning/deprecated' require 'jsduck/warning/all' require 'jsduck/warning/warn_exception' Loading @@ -19,7 +20,6 @@ module JsDuck [:global, "Member doesn't belong to any class"], [:inheritdoc, "@inheritdoc referring to unknown class or member"], [:extend, "@extend/mixin/requires/uses referring to unknown class"], [:tag, "Use of unsupported @tag"], [:tag_repeated, "An @tag used multiple times, but only once allowed"], [:tag_syntax, "@tag syntax error"], [:link, "{@link} to unknown class or member"], Loading Loading @@ -52,6 +52,9 @@ module JsDuck register(w[0], Warning::Basic.new(w[0], w[1])) end # :tag warning register(:tag, Warning::Tag.new) # :nodoc warning register(:nodoc, Warning::Nodoc.new) Loading lib/jsduck/warning/tag.rb 0 → 100644 +57 −0 Original line number Diff line number Diff line module JsDuck module Warning # Unknown tag warning. class Tag # Creates the :tag warning type def initialize @rules = [] # disable by default set(false) end # Enables or disables a particular sub-warning def set(enabled, path_pattern=nil, tagnames=[]) @rules.unshift({ :enabled => enabled, :tagnames => tagnames, :path_re => path_pattern ? Regexp.new(Regexp.escape(path_pattern)) : nil }) end # True when the warning is enabled for the given filename and # params combination where params contains one tagname. def enabled?(filename="", params=[]) tagname = params[0] # Filter out the most recently added rule that applies to our current item match = @rules.find do |r| (r[:tagnames].empty? || r[:tagnames].include?(tagname)) && (r[:path_re].nil? || r[:path_re] =~ filename) end return match[:enabled] end # Extensive documentation for :nodoc warning def doc [ "", " +tag(<name1>,<name2>,...) - Use of unsupported @tag", "", " This warning type can optionally take a list of tag names", " to limit its effect to only these tags.", "", " So, to disable warnings for JavaDoc tags @file and @overview", " which aren't supported by JSDuck:", "", " --warnings='-tag(file,overview)'", "", ] end end end end spec/warning_registry_spec.rb +42 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,48 @@ describe JsDuck::Warning::Registry do end end describe "after enabling :tag warning" do before do warnings.set(:tag, true) end it "has the :tag warning enabled for a @footag" do warnings.enabled?(:tag, "foo.js", [:footag]).should == true end describe "and disabling it for @footag and @bartag" do before do warnings.set(:tag, false, nil, [:footag, :bartag]) end it "has the :tag warning disabled for a @footag" do warnings.enabled?(:tag, "bar.js", [:footag]).should == false end it "has the :tag warning disabled for a @bartag" do warnings.enabled?(:tag, "bar.js", [:bartag]).should == false end it "has the :tag warning still enabled for a @mytag" do warnings.enabled?(:tag, "bar.js", [:mytag]).should == true end describe "and enabling it for files in /foo/" do before do warnings.set(:tag, true, "/foo/") end it "has the :tag warning enabled for a @footag in /foo/" do warnings.enabled?(:tag, "/foo/bar.js", [:footag]).should == true end it "still has the :tag warning disabled for a @footag outside of /foo/" do warnings.enabled?(:tag, "bar.js", [:footag]).should == false end end end end describe "after enabling :nodoc warning" do before do warnings.set(:nodoc, true) Loading Loading
lib/jsduck/doc/parser.rb +1 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,7 @@ module JsDuck skip_white else warn(:tag, "Unsupported tag: @#{name}") warn(:tag, "Unsupported tag: @#{name}", [name.to_sym]) @multiline_tag[:doc] += "@" end end Loading
lib/jsduck/doc/scanner.rb +2 −2 Original line number Diff line number Diff line Loading @@ -73,8 +73,8 @@ module JsDuck end # Prints a warning message def warn(type, msg) Logger.warn(type, msg, @position) def warn(type, msg, params=[]) Logger.warn(type, msg, @position, params) end end Loading
lib/jsduck/warning/registry.rb +4 −1 Original line number Diff line number Diff line require 'jsduck/warning/basic' require 'jsduck/warning/nodoc' require 'jsduck/warning/tag' require 'jsduck/warning/deprecated' require 'jsduck/warning/all' require 'jsduck/warning/warn_exception' Loading @@ -19,7 +20,6 @@ module JsDuck [:global, "Member doesn't belong to any class"], [:inheritdoc, "@inheritdoc referring to unknown class or member"], [:extend, "@extend/mixin/requires/uses referring to unknown class"], [:tag, "Use of unsupported @tag"], [:tag_repeated, "An @tag used multiple times, but only once allowed"], [:tag_syntax, "@tag syntax error"], [:link, "{@link} to unknown class or member"], Loading Loading @@ -52,6 +52,9 @@ module JsDuck register(w[0], Warning::Basic.new(w[0], w[1])) end # :tag warning register(:tag, Warning::Tag.new) # :nodoc warning register(:nodoc, Warning::Nodoc.new) Loading
lib/jsduck/warning/tag.rb 0 → 100644 +57 −0 Original line number Diff line number Diff line module JsDuck module Warning # Unknown tag warning. class Tag # Creates the :tag warning type def initialize @rules = [] # disable by default set(false) end # Enables or disables a particular sub-warning def set(enabled, path_pattern=nil, tagnames=[]) @rules.unshift({ :enabled => enabled, :tagnames => tagnames, :path_re => path_pattern ? Regexp.new(Regexp.escape(path_pattern)) : nil }) end # True when the warning is enabled for the given filename and # params combination where params contains one tagname. def enabled?(filename="", params=[]) tagname = params[0] # Filter out the most recently added rule that applies to our current item match = @rules.find do |r| (r[:tagnames].empty? || r[:tagnames].include?(tagname)) && (r[:path_re].nil? || r[:path_re] =~ filename) end return match[:enabled] end # Extensive documentation for :nodoc warning def doc [ "", " +tag(<name1>,<name2>,...) - Use of unsupported @tag", "", " This warning type can optionally take a list of tag names", " to limit its effect to only these tags.", "", " So, to disable warnings for JavaDoc tags @file and @overview", " which aren't supported by JSDuck:", "", " --warnings='-tag(file,overview)'", "", ] end end end end
spec/warning_registry_spec.rb +42 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,48 @@ describe JsDuck::Warning::Registry do end end describe "after enabling :tag warning" do before do warnings.set(:tag, true) end it "has the :tag warning enabled for a @footag" do warnings.enabled?(:tag, "foo.js", [:footag]).should == true end describe "and disabling it for @footag and @bartag" do before do warnings.set(:tag, false, nil, [:footag, :bartag]) end it "has the :tag warning disabled for a @footag" do warnings.enabled?(:tag, "bar.js", [:footag]).should == false end it "has the :tag warning disabled for a @bartag" do warnings.enabled?(:tag, "bar.js", [:bartag]).should == false end it "has the :tag warning still enabled for a @mytag" do warnings.enabled?(:tag, "bar.js", [:mytag]).should == true end describe "and enabling it for files in /foo/" do before do warnings.set(:tag, true, "/foo/") end it "has the :tag warning enabled for a @footag in /foo/" do warnings.enabled?(:tag, "/foo/bar.js", [:footag]).should == true end it "still has the :tag warning disabled for a @footag outside of /foo/" do warnings.enabled?(:tag, "bar.js", [:footag]).should == false end end end end describe "after enabling :nodoc warning" do before do warnings.set(:nodoc, true) Loading