jsduck 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTQ4ZGE0ZGEzMTQxNDY1ZjhiY2FhNTliMmJjNTQ0OGY2NTZkY2VhMA==
5
+ data.tar.gz: !binary |-
6
+ ZWEzMjZmMGEzOTBmOGM4OGQ4NzZiY2NhMjA5OTZkZGVlMzdhMTc4NQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZjA3N2ZjODkwZjNhNjBiNWExNTNlZjI0YzA4Y2EyZmZjZDk5MWUyMzY1Y2Iy
10
+ NTlmYWY0MjJlODhjZjgwZGE3ZmY2YzZjZWI3MWE5OWVhM2ZjN2Q3YWJlODQy
11
+ Zjg0OGM1NDZmNTdkNDExNmJlN2ZmZTU4ODkxYWI1YTM3MWFhMjk=
12
+ data.tar.gz: !binary |-
13
+ NTc0ZDQ1NDMxYTU5MDhiMTYyMTFlN2RiODNlYTczYThkZjUzMDFkNzk4NTU3
14
+ NzY5YzVkNDMyYzA0NWI1MjM5NWQ4M2VkYzI2ZDcxNzQ0MGI0Y2Y5OWVkNDYz
15
+ MjE0MjFiZjRjNWIxNWYzMjcxMWU2YjNkMjY3M2VmNTZmMzg2ODY=
@@ -14,6 +14,7 @@ require 'jsduck/process/versions'
14
14
  require 'jsduck/process/return_values'
15
15
  require 'jsduck/process/fires'
16
16
  require 'jsduck/process/lint'
17
+ require 'jsduck/process/no_doc'
17
18
  require 'jsduck/process/circular_deps'
18
19
 
19
20
  module JsDuck
@@ -71,6 +72,7 @@ module JsDuck
71
72
  Process::ReturnValues.new(relations).process_all!
72
73
  Process::Fires.new(relations).process_all!
73
74
  Process::Lint.new(relations).process_all!
75
+ Process::NoDoc.new(relations).process_all!
74
76
  relations
75
77
  end
76
78
 
@@ -1,5 +1,7 @@
1
1
  require 'jsduck/util/singleton'
2
2
  require 'jsduck/util/os'
3
+ require 'jsduck/warning/registry'
4
+ require 'jsduck/warning/warn_exception'
3
5
 
4
6
  module JsDuck
5
7
 
@@ -18,51 +20,7 @@ module JsDuck
18
20
  @verbose = false
19
21
  @colors = nil
20
22
 
21
- @warning_docs = [
22
- [:global, "Member doesn't belong to any class"],
23
- [:inheritdoc, "@inheritdoc referring to unknown class or member"],
24
- [:extend, "@extend/mixin/requires/uses referring to unknown class"],
25
- [:tag, "Use of unsupported @tag"],
26
- [:tag_repeated, "An @tag used multiple times, but only once allowed"],
27
- [:tag_syntax, "@tag syntax error"],
28
- [:link, "{@link} to unknown class or member"],
29
- [:link_ambiguous, "{@link} is ambiguous"],
30
- [:link_auto, "Auto-detected link to unknown class or member"],
31
- [:html, "Unclosed HTML tag."],
32
-
33
- [:alt_name, "Name used as both classname and alternate classname"],
34
- [:name_missing, "Member or parameter has no name"],
35
- [:no_doc, "Public class without documentation"],
36
- [:no_doc_member, "Public member without documentation"],
37
- [:no_doc_param, "Parameter of public member without documentation"],
38
- [:dup_param, "Method has two parameters with the same name"],
39
- [:dup_member, "Class has two members with the same name"],
40
- [:req_after_opt, "Required parameter comes after optional"],
41
- [:param_count, "Less parameters documented than detected from code"],
42
- [:subproperty, "@param foo.bar where foo param doesn't exist"],
43
- [:sing_static, "Singleton class member marked as @static"],
44
- [:type_syntax, "Syntax error in {type definition}"],
45
- [:type_name, "Unknown type referenced in {type definition}"],
46
- [:enum, "Enum with invalid values or no values at all"],
47
- [:fires, "@fires references unknown event"],
48
-
49
- [:image, "{@img} referring to missing file"],
50
- [:image_unused, "An image exists in --images dir that's not used"],
51
- [:cat_old_format, "Categories file uses old deprecated format"],
52
- [:cat_no_match, "Class pattern in categories file matches nothing"],
53
- [:cat_class_missing, "Class is missing from categories file"],
54
- [:guide, "Guide is missing from --guides dir"],
55
-
56
- [:aside, "Problem with @aside tag"],
57
- [:hide, "Problem with @hide tag"],
58
- ]
59
- # Turn off all warnings by default.
60
- # This is good for testing.
61
- # When running JSDuck app, the Options class enables most warnings.
62
- @warnings = {}
63
- @warning_docs.each do |w|
64
- @warnings[w[0]] = {:enabled => false, :patterns => []}
65
- end
23
+ @warnings = Warning::Registry.new
66
24
 
67
25
  @shown_warnings = {}
68
26
  end
@@ -77,31 +35,17 @@ module JsDuck
77
35
  # Enables or disables a particular warning
78
36
  # or all warnings when type == :all.
79
37
  # Additionally a filename pattern can be specified.
80
- def set_warning(type, enabled, pattern=nil)
81
- if type == :all
82
- # When used with a pattern, only add the pattern to the rules
83
- # where it can have an effect - otherwise we get a warning.
84
- @warnings.each_key do |key|
85
- set_warning(key, enabled, pattern) unless pattern && @warnings[key][:enabled] == enabled
86
- end
87
- elsif @warnings.has_key?(type)
88
- if pattern
89
- if @warnings[type][:enabled] == enabled
90
- warn(nil, "Warning rule '#{enabled ? '+' : '-'}#{type}:#{pattern}' has no effect")
91
- else
92
- @warnings[type][:patterns] << Regexp.new(Regexp.escape(pattern))
93
- end
94
- else
95
- @warnings[type] = {:enabled => enabled, :patterns => []}
96
- end
97
- else
98
- warn(nil, "Warning of type '#{type}' doesn't exist")
38
+ def set_warning(type, enabled, pattern=nil, params=[])
39
+ begin
40
+ @warnings.set(type, enabled, pattern, params)
41
+ rescue Warning::WarnException => e
42
+ warn(nil, e.message)
99
43
  end
100
44
  end
101
45
 
102
46
  # get documentation for all warnings
103
47
  def doc_warnings
104
- @warning_docs.map {|w| " #{@warnings[w[0]][:enabled] ? '+' : '-'}#{w[0]} - #{w[1]}" }
48
+ @warnings.doc
105
49
  end
106
50
 
107
51
  # Prints warning message.
@@ -125,46 +69,24 @@ module JsDuck
125
69
  filename = filename[:filename]
126
70
  end
127
71
 
128
- msg = paint(:yellow, "Warning: ") + format(filename, line) + " " + msg
129
-
130
72
  if warning_enabled?(type, filename)
131
- if !@shown_warnings[msg]
132
- $stderr.puts msg
133
- @shown_warnings[msg] = true
134
- end
73
+ print_warning(msg, filename, line)
135
74
  end
136
75
 
137
76
  return false
138
77
  end
139
78
 
140
- # True when the warning is enabled for the given type and filename
141
- # combination.
142
- def warning_enabled?(type, filename)
143
- if type == nil
144
- true
145
- elsif !@warnings.has_key?(type)
146
- warn(nil, "Unknown warning type #{type}")
147
- false
148
- else
149
- rule = @warnings[type]
150
- if rule[:patterns].any? {|re| filename =~ re }
151
- !rule[:enabled]
152
- else
153
- rule[:enabled]
154
- end
155
- end
156
- end
157
-
158
- # Formats filename and line number for output
159
- def format(filename=nil, line=nil)
160
- out = ""
161
- if filename
162
- out = Util::OS.windows? ? filename.gsub('/', '\\') : filename
163
- if line
164
- out += ":#{line}:"
165
- end
79
+ # Prints :nodoc warning message.
80
+ #
81
+ # Because the :nodoc warning needs different parameters, for now
82
+ # we're using a separate method specially for these.
83
+ def warn_nodoc(type, visibility, msg, file)
84
+ filename = file[:filename]
85
+ line = file[:linenr]
86
+
87
+ if @warnings.enabled?(:nodoc, filename, [type, visibility])
88
+ print_warning(msg, filename, line)
166
89
  end
167
- paint(:magenta, out)
168
90
  end
169
91
 
170
92
  # Prints fatal error message with backtrace.
@@ -202,6 +124,37 @@ module JsDuck
202
124
 
203
125
  CLEAR = "\e[0m"
204
126
 
127
+ def warning_enabled?(type, filename)
128
+ if type == nil
129
+ true
130
+ elsif !@warnings.has?(type)
131
+ warn(nil, "Unknown warning type #{type}")
132
+ else
133
+ @warnings.enabled?(type, filename)
134
+ end
135
+ end
136
+
137
+ def print_warning(msg, filename, line)
138
+ warning = paint(:yellow, "Warning: ") + format(filename, line) + " " + msg
139
+
140
+ if !@shown_warnings[warning]
141
+ $stderr.puts warning
142
+ @shown_warnings[warning] = true
143
+ end
144
+ end
145
+
146
+ # Formats filename and line number for output
147
+ def format(filename=nil, line=nil)
148
+ out = ""
149
+ if filename
150
+ out = Util::OS.windows? ? filename.gsub('/', '\\') : filename
151
+ if line
152
+ out += ":#{line}:"
153
+ end
154
+ end
155
+ paint(:magenta, out)
156
+ end
157
+
205
158
  # Helper for doing colored output in UNIX terminal
206
159
  #
207
160
  # Only does color output when STDERR is attached to TTY
@@ -27,7 +27,7 @@ module JsDuck
27
27
  "<div id='news-content' style='#{style}'>",
28
28
  "<div class='section'>",
29
29
  "<h1>New in this version</h1>",
30
- render_columns(@new_items),
30
+ render_news(@new_items),
31
31
  "<div style='clear:both'></div>",
32
32
  "</div>",
33
33
  "</div>",
@@ -91,6 +91,14 @@ module JsDuck
91
91
  str[0,1].upcase + str[1..-1]
92
92
  end
93
93
 
94
+ def render_news(new_items)
95
+ if new_items.length > 0
96
+ render_columns(new_items)
97
+ else
98
+ "<h3>Nothing new.</h3>"
99
+ end
100
+ end
101
+
94
102
  def render_columns(new_items)
95
103
  align = ["left-column", "middle-column", "right-column"]
96
104
  i = -1
@@ -6,6 +6,7 @@ require 'jsduck/util/io'
6
6
  require 'jsduck/util/parallel'
7
7
  require 'jsduck/tag_registry'
8
8
  require 'jsduck/js/ext_patterns'
9
+ require 'jsduck/warning/parser'
9
10
 
10
11
  module JsDuck
11
12
 
@@ -98,7 +99,7 @@ module JsDuck
98
99
  ]
99
100
  @ext4_events = nil
100
101
 
101
- @version = "5.1.0"
102
+ @version = "5.2.0"
102
103
  # Customizing output
103
104
  @title = "Documentation - JSDuck"
104
105
  @header = "<strong>Documentation</strong> JSDuck"
@@ -148,7 +149,7 @@ module JsDuck
148
149
  Logger.set_warning(:link_auto, false)
149
150
  Logger.set_warning(:param_count, false)
150
151
  Logger.set_warning(:fires, false)
151
- Logger.set_warning(:no_doc_param, false)
152
+ Logger.set_warning(:nodoc, false)
152
153
 
153
154
  @optparser = create_option_parser
154
155
  end
@@ -672,7 +673,7 @@ module JsDuck
672
673
  Logger.verbose = true
673
674
  end
674
675
 
675
- opts.on('--warnings=+A,-B,+C', Array,
676
+ opts.on('--warnings=+A,-B,+C',
676
677
  "Turns warnings selectively on/off.",
677
678
  "",
678
679
  " +all - to turn on all warnings.",
@@ -696,13 +697,12 @@ module JsDuck
696
697
  "(Those with '+' in front of them default to on)",
697
698
  "",
698
699
  *Logger.doc_warnings) do |warnings|
699
- warnings.each do |op|
700
- if op =~ /^([-+]?)(\w+)(?::(.*))?$/
701
- enable = !($1 == "-")
702
- name = $2.to_sym
703
- path = $3
704
- Logger.set_warning(name, enable, path)
700
+ begin
701
+ Warning::Parser.new(warnings).parse.each do |w|
702
+ Logger.set_warning(w[:type], w[:enabled], w[:path], w[:params])
705
703
  end
704
+ rescue Warning::WarnException => e
705
+ Logger.warn(nil, e.message)
706
706
  end
707
707
  end
708
708
 
@@ -92,7 +92,7 @@ module JsDuck
92
92
  :params => [{
93
93
  :type => cfg[:type],
94
94
  :name => cfg[:name],
95
- :doc => "",
95
+ :doc => "The new value.",
96
96
  }],
97
97
  :id => "method-" + name,
98
98
  }, cfg)
@@ -1,5 +1,4 @@
1
1
  require 'jsduck/logger'
2
- require 'jsduck/class'
3
2
 
4
3
  module JsDuck
5
4
  module Process
@@ -14,7 +13,6 @@ module JsDuck
14
13
 
15
14
  # Runs the linter
16
15
  def process_all!
17
- warn_no_doc
18
16
  warn_unnamed
19
17
  warn_optional_params
20
18
  warn_duplicate_params
@@ -37,32 +35,6 @@ module JsDuck
37
35
  end
38
36
  end
39
37
 
40
- # print warning for each class or public member with no name
41
- def warn_no_doc
42
- @relations.each do |cls|
43
-
44
- if cls[:doc] == "" && !cls[:private]
45
- warn(:no_doc, "No documentation for #{cls[:name]}", cls)
46
- end
47
-
48
- cls.all_local_members.each do |member|
49
- if !member[:private] && !member[:hide] && !JsDuck::Class.constructor?(member)
50
- if member[:doc] == ""
51
- warn(:no_doc_member, "No documentation for #{member[:owner]}##{member[:name]}", member)
52
- end
53
-
54
- (member[:params] || []).each do |p|
55
- if p[:doc] == ""
56
- warn(:no_doc_param, "No documentation for parameter #{p[:name]} of #{member[:owner]}##{member[:name]}", member)
57
- end
58
- end
59
-
60
- end
61
- end
62
-
63
- end
64
- end
65
-
66
38
  # print warning for each non-optional parameter that follows an optional parameter
67
39
  def warn_optional_params
68
40
  each_member do |member|
@@ -0,0 +1,50 @@
1
+ require 'jsduck/logger'
2
+ require 'jsduck/class'
3
+
4
+ module JsDuck
5
+ module Process
6
+
7
+ # Reports missing documentation
8
+ class NoDoc
9
+ def initialize(relations)
10
+ @relations = relations
11
+ end
12
+
13
+ # Prints warning for each class or public member with no name
14
+ def process_all!
15
+ @relations.each do |cls|
16
+
17
+ if cls[:doc] == ""
18
+ warn(:class, "No documentation for #{cls[:name]}", cls)
19
+ end
20
+
21
+ cls.all_local_members.each do |member|
22
+ if !member[:hide] && !JsDuck::Class.constructor?(member)
23
+ if member[:doc] == ""
24
+ warn(:member, "No documentation for #{member[:owner]}##{member[:name]}", member)
25
+ end
26
+
27
+ (member[:params] || []).each do |p|
28
+ if p[:doc] == ""
29
+ warn(:param, "No documentation for parameter #{p[:name]} of #{member[:owner]}##{member[:name]}", member)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def warn(type, msg, owner)
42
+ visibility = owner[:private] ? :private : (owner[:protected] ? :protected : :public)
43
+
44
+ Logger.warn_nodoc(type, visibility, msg, owner[:files][0])
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -42,6 +42,8 @@ module JsDuck::Tag
42
42
  end
43
43
 
44
44
  def to_html(m)
45
+ return unless m[:fires] && m[:fires].length > 0
46
+
45
47
  return [
46
48
  "<h3 class='pa'>Fires</h3>",
47
49
  "<ul>",
@@ -25,7 +25,17 @@ module JsDuck
25
25
 
26
26
  # Reads given filename into string
27
27
  def self.read(filename)
28
- File.open(filename, "r:"+@@encoding) {|f| f.read }
28
+ File.open(filename, "r:"+@@encoding) {|f| self.strip_utf8_bom(f.read) }
29
+ end
30
+
31
+ # Takes care of removing UTF-8 byte order mark in Ruby <= 1.8 which
32
+ # doesn't have built-in encodings support.
33
+ def self.strip_utf8_bom(string)
34
+ if "".respond_to?(:encoding)
35
+ string
36
+ else
37
+ string.sub(/\A\xEF\xBB\xBF/, "")
38
+ end
29
39
  end
30
40
 
31
41
  end
@@ -0,0 +1,36 @@
1
+ module JsDuck
2
+ module Warning
3
+
4
+ # A composite warning, encompassing all the other warning types.
5
+ class All
6
+
7
+ # Creates a deprecated warning with a mapping to :nodoc warning
8
+ # type with given parameters. The warning is disabled by
9
+ # default.
10
+ def initialize(warnings)
11
+ @warnings = warnings
12
+ end
13
+
14
+ # Enables/disables all warnings.
15
+ def set(enabled, path_pattern=nil, params=[])
16
+ # When used with a path_pattern, only add the pattern to the rules
17
+ # where it can have an effect - otherwise we get a warning.
18
+ @warnings.each do |w|
19
+ w.set(enabled, path_pattern, params) unless path_pattern && w.enabled? == enabled
20
+ end
21
+ end
22
+
23
+ # Doesn't make sense to check if the :all warning is enabled.
24
+ def enabled?(filename="", params=[])
25
+ raise "Warning type 'all' must not be checked for enabled/disabled"
26
+ end
27
+
28
+ # The all-warning is documented separately
29
+ def doc
30
+ nil
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end