Class: JsDuck::Warning::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/warning/registry.rb

Overview

Warnings management

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



13
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
# File 'lib/jsduck/warning/registry.rb', line 13

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, "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"],
    [: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_old_format, "Categories file uses old deprecated format"],
    [: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

  # :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

#docObject

get documentation for all warnings



89
90
91
# File 'lib/jsduck/warning/registry.rb', line 89

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.

Returns:

  • (Boolean)


95
96
97
# File 'lib/jsduck/warning/registry.rb', line 95

def enabled?(type, filename, params=[])
  @warnings_map[type].enabled?(filename, params)
end

#has?(type) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/jsduck/warning/registry.rb', line 99

def has?(type)
  @warnings_map.has_key?(type)
end

#register(type, warning) ⇒ Object



73
74
75
76
# File 'lib/jsduck/warning/registry.rb', line 73

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.



80
81
82
83
84
85
86
# File 'lib/jsduck/warning/registry.rb', line 80

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