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_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.
10 11 12 |
# File 'lib/jsduck/process/lint.rb', line 10 def initialize(relations) @relations = relations end |
Instance Attribute Details
#relations ⇒ Object
Returns the value of attribute relations.
8 9 10 |
# File 'lib/jsduck/process/lint.rb', line 8 def relations @relations end |
Instance Method Details
#each_member(&block) ⇒ Object
Loops through all members of all classes
106 107 108 |
# File 'lib/jsduck/process/lint.rb', line 106 def each_member(&block) @relations.each {|cls| cls.all_local_members.each(&block) } end |
#process_all! ⇒ Object
Runs the linter
15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
Prints warning + filename and linenumber from doc-context
111 112 113 |
# File 'lib/jsduck/process/lint.rb', line 111 def warn(type, msg, member) Logger.warn(type, msg, member[:files][0]) end |
#warn_duplicate_members ⇒ Object
print warnings for duplicate member names
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 ⇒ Object
print warnings for duplicate parameter names
54 55 56 57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
print warnings for enums with no values
97 98 99 100 101 102 103 |
# 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 ⇒ Object
print warning for each non-optional parameter that follows an optional parameter
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 ⇒ Object
Print warnings for static members in singleton classes
86 87 88 89 90 91 92 93 94 |
# 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 ⇒ Object
print warning for each member or parameter with no name
25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 |