class JsDuck::Process::Lint
Reports bugs and problems in documentation
Attributes
relations[RW]
Public Class Methods
new(relations)
click to toggle source
# File lib/jsduck/process/lint.rb, line 10 def initialize(relations) @relations = relations end
Public Instance Methods
each_member(&block)
click to toggle source
Loops through all members of all classes
# File lib/jsduck/process/lint.rb, line 106 def each_member(&block) @relations.each {|cls| cls.all_local_members.each(&block) } end
process_all!()
click to toggle source
Runs the linter
# File lib/jsduck/process/lint.rb, line 15 def process_all! warn_unnamed warn_optional_params warn_duplicate_params warn_duplicate_members warn_singleton_statics warn_empty_enums end
warn(type, msg, member)
click to toggle source
Prints warning + filename and linenumber from doc-context
# File lib/jsduck/process/lint.rb, line 111 def warn(type, msg, member) Logger.warn(type, msg, member[:files][0]) end
warn_duplicate_members()
click to toggle source
print warnings for duplicate member names
# File lib/jsduck/process/lint.rb, line 67 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()
click to toggle source
print warnings for duplicate parameter names
# File lib/jsduck/process/lint.rb, line 54 def warn_duplicate_params each_member do |member| params = {} Array(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()
click to toggle source
print warnings for enums with no values
# File lib/jsduck/process/lint.rb, line 97 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_optional_params()
click to toggle source
print warning for each non-optional parameter that follows an optional parameter
# File lib/jsduck/process/lint.rb, line 39 def warn_optional_params each_member do |member| if member[:tagname] == :method optional_found = false Array(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()
click to toggle source
Print warnings for static members in singleton classes
# File lib/jsduck/process/lint.rb, line 86 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()
click to toggle source
print warning for each member or parameter with no name
# File lib/jsduck/process/lint.rb, line 25 def warn_unnamed each_member do |member| if !member[:name] || member[:name] == "" warn(:name_missing, "Unnamed #{member[:tagname]}", member) end Array(member[:params]).each do |p| if !p[:name] || p[:name] == "" warn(:name_missing, "Unnamed parameter", member) end end end end