Class: JsDuck::Process::Lint
- Inherits:
-
Object
- Object
- JsDuck::Process::Lint
- Defined in:
- lib/jsduck/process/lint.rb
Overview
Reports bugs and problems in documentation
Instance Attribute Summary collapse
-
#relations ⇒ Object
Returns the value of attribute relations.
Instance Method Summary collapse
-
#each_member(&block) ⇒ Object
Loops through all members of all classes.
-
#initialize(relations) ⇒ Lint
constructor
A new instance of Lint.
-
#process_all! ⇒ Object
Runs the linter.
-
#warn(type, msg, member) ⇒ Object
Prints warning + filename and linenumber from doc-context.
-
#warn_duplicate_members ⇒ Object
print warnings for duplicate member names.
-
#warn_duplicate_params ⇒ Object
print warnings for duplicate parameter names.
-
#warn_empty_enums ⇒ Object
print warnings for enums with no values.
-
#warn_no_doc ⇒ Object
print warning for each class or public member with no name.
-
#warn_optional_params ⇒ Object
print warning for each non-optional parameter that follows an optional parameter.
-
#warn_singleton_statics ⇒ Object
Print warnings for static members in singleton classes.
-
#warn_unnamed ⇒ Object
print warning for each member or parameter with no name.
Constructor Details
#initialize(relations) ⇒ Lint
Returns a new instance of Lint.
11 12 13 |
# File 'lib/jsduck/process/lint.rb', line 11 def initialize(relations) @relations = relations end |
Instance Attribute Details
#relations ⇒ Object
Returns the value of attribute relations.
9 10 11 |
# File 'lib/jsduck/process/lint.rb', line 9 def relations @relations end |
Instance Method Details
#each_member(&block) ⇒ Object
Loops through all members of all classes
134 135 136 |
# File 'lib/jsduck/process/lint.rb', line 134 def each_member(&block) @relations.each {|cls| cls.all_local_members.each(&block) } end |
#process_all! ⇒ Object
Runs the linter
16 17 18 19 20 21 22 23 24 |
# File 'lib/jsduck/process/lint.rb', line 16 def process_all! warn_no_doc warn_unnamed warn_optional_params warn_duplicate_params warn_duplicate_members warn_singleton_statics warn_empty_enums end |
#warn(type, msg, member) ⇒ Object
Prints warning + filename and linenumber from doc-context
139 140 141 |
# File 'lib/jsduck/process/lint.rb', line 139 def warn(type, msg, member) Logger.warn(type, msg, member[:files][0]) end |
#warn_duplicate_members ⇒ Object
print warnings for duplicate member names
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/jsduck/process/lint.rb', line 95 def warn_duplicate_members @relations.each do |cls| members = {:members => {}, :statics => {}} cls.all_local_members.each do |m| group = m[:static] ? :statics : :members type = m[:tagname] name = m[:name] hash = members[group][type] || {} if hash[name] warn(:dup_member, "Duplicate #{type} name #{name}", hash[name]) warn(:dup_member, "Duplicate #{type} name #{name}", m) end hash[name] = m members[group][type] = hash end end end |
#warn_duplicate_params ⇒ Object
print warnings for duplicate parameter names
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/jsduck/process/lint.rb', line 82 def warn_duplicate_params each_member do |member| params = {} (member[:params] || []).each do |p| if params[p[:name]] warn(:dup_param, "Duplicate parameter name #{p[:name]}", member) end params[p[:name]] = true end end end |
#warn_empty_enums ⇒ Object
print warnings for enums with no values
125 126 127 128 129 130 131 |
# File 'lib/jsduck/process/lint.rb', line 125 def warn_empty_enums @relations.each do |cls| if cls[:enum] && cls[:members].length == 0 warn(:enum, "Enum #{cls[:name]} defined without values in it", cls) end end end |
#warn_no_doc ⇒ Object
print warning for each class or public member with no name
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jsduck/process/lint.rb', line 41 def warn_no_doc @relations.each do |cls| if cls[:doc] == "" && !cls[:private] warn(:no_doc, "No documentation for #{cls[:name]}", cls) end cls.all_local_members.each do |member| if !member[:private] && !member[:hide] && !JsDuck::Class.constructor?(member) if member[:doc] == "" warn(:no_doc_member, "No documentation for #{member[:owner]}##{member[:name]}", member) end (member[:params] || []).each do |p| if p[:doc] == "" warn(:no_doc_param, "No documentation for parameter #{p[:name]} of #{member[:owner]}##{member[:name]}", member) end end end end end end |
#warn_optional_params ⇒ Object
print warning for each non-optional parameter that follows an optional parameter
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jsduck/process/lint.rb', line 67 def warn_optional_params each_member do |member| if member[:tagname] == :method optional_found = false member[:params].each do |p| if optional_found && !p[:optional] warn(:req_after_opt, "Optional param followed by regular param #{p[:name]}", member) end optional_found = optional_found || p[:optional] end end end end |
#warn_singleton_statics ⇒ Object
Print warnings for static members in singleton classes
114 115 116 117 118 119 120 121 122 |
# File 'lib/jsduck/process/lint.rb', line 114 def warn_singleton_statics @relations.each do |cls| if cls[:singleton] cls.find_members({:local => true, :static => true}).each do |m| warn(:sing_static, "Static members don't make sense in singleton class #{cls[:name]}", m) end end end end |
#warn_unnamed ⇒ Object
print warning for each member or parameter with no name
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jsduck/process/lint.rb', line 27 def warn_unnamed each_member do |member| if !member[:name] || member[:name] == "" warn(:name_missing, "Unnamed #{member[:tagname]}", member) end (member[:params] || []).each do |p| if !p[:name] || p[:name] == "" warn(:name_missing, "Unnamed parameter", member) end end end end |