Class: JsDuck::Warning::Registry
- Inherits:
-
Object
- Object
- JsDuck::Warning::Registry
- Defined in:
- lib/jsduck/warning/registry.rb
Overview
Warnings management
Instance Method Summary collapse
-
#doc ⇒ Object
get documentation for all warnings.
-
#enabled?(type, filename, params = []) ⇒ Boolean
True when the warning is enabled for the given type and filename combination.
- #has?(type) ⇒ Boolean
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(type, warning) ⇒ Object
-
#set(type, enabled, path_pattern = nil, params = []) ⇒ Object
Enables or disables a particular warning type.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jsduck/warning/registry.rb', line 14 def initialize @warnings = [] @warnings_map = {} # Basic warnings [ [: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_repeated, "An @tag used multiple times, but only once allowed"], [:tag_syntax, "@tag syntax error"], [:link, "{@link} to unknown class or member"], [:link_ambiguous, "{@link} is ambiguous"], [:link_auto, "Auto-detected link to unknown class or member"], [:html, "Unclosed HTML tag"], [:alt_name, "Name used as both classname and alternate classname"], [:name_missing, "Member or parameter has no name"], [:dup_param, "Method has two parameters with the same name"], [:dup_member, "Class has two members with the same name"], [:req_after_opt, "Required parameter comes after optional"], [:param_count, "Less parameters documented than detected from code"], [:subproperty, "@param foo.bar where foo param doesn't exist"], [:sing_static, "Singleton class member marked as @static"], [:type_syntax, "Syntax error in {type definition}"], [:type_name, "Unknown type referenced in {type definition}"], [:enum, "Enum with invalid values or no values at all"], [:fires, "@fires references unknown event"], [:image, "{@img} referring to missing file"], [:image_unused, "An image exists in --images dir that's not used"], [:cat_no_match, "Class pattern in categories file matches nothing"], [:cat_class_missing, "Class is missing from categories file"], [:guide, "Guide is missing from --guides dir"], [:aside, "Problem with @aside tag"], [:hide, "Problem with @hide tag"], ].each do |w| 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) # :all warning (encompasses all other warning types) register(:all, Warning::All.new(@warnings.clone)) # :deprecated warnings (linking to :nodoc warning) [ {:type => :no_doc, :msg => "Alias for nodoc(class,public)", :params => [:class, :public]}, {:type => :no_doc_member, :msg => "Alias for nodoc(member,public)", :params => [:member, :public]}, {:type => :no_doc_param, :msg => "Alias for nodoc(param,public)", :params => [:param, :public]}, ].each do |w| register(w[:type], Warning::Deprecated.new(w[:type], w[:msg], @warnings_map[:nodoc], w[:params])) end end |
Instance Method Details
#doc ⇒ Object
get documentation for all warnings
91 92 93 |
# File 'lib/jsduck/warning/registry.rb', line 91 def doc @warnings.map {|w| w.doc }.compact.flatten end |
#enabled?(type, filename, params = []) ⇒ Boolean
True when the warning is enabled for the given type and filename combination.
97 98 99 |
# File 'lib/jsduck/warning/registry.rb', line 97 def enabled?(type, filename, params=[]) @warnings_map[type].enabled?(filename, params) end |
#has?(type) ⇒ Boolean
101 102 103 |
# File 'lib/jsduck/warning/registry.rb', line 101 def has?(type) @warnings_map.has_key?(type) end |
#register(type, warning) ⇒ Object
75 76 77 78 |
# File 'lib/jsduck/warning/registry.rb', line 75 def register(type, warning) @warnings << warning @warnings_map[type] = warning end |
#set(type, enabled, path_pattern = nil, params = []) ⇒ Object
Enables or disables a particular warning type. Additionally a filename pattern and params for the warning can be specified.
82 83 84 85 86 87 88 |
# File 'lib/jsduck/warning/registry.rb', line 82 def set(type, enabled, path_pattern=nil, params=[]) if @warnings_map[type] @warnings_map[type].set(enabled, path_pattern, params) else raise WarnException, "Warning of type '#{type}' doesn't exist" end end |