Class: Cane::DocCheck
- Inherits:
-
Struct
- Object
- Struct
- Cane::DocCheck
- Defined in:
- lib/cane/doc_check.rb
Overview
Creates violations for class definitions that do not have an explantory comment immediately preceeding.
Constant Summary collapse
- MAGIC_COMMENT_REGEX =
Stolen from ERB source.
%r"coding\s*[=:]\s*([[:alnum:]\-_]+)"
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
- #class_definition?(line) ⇒ Boolean
- #comment?(line) ⇒ Boolean
- #extract_class_name(line) ⇒ Object
- #file_names ⇒ Object
- #find_violations(file_name) ⇒ Object
- #violations ⇒ Object
- #worker ⇒ Object
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts
7 8 9 |
# File 'lib/cane/doc_check.rb', line 7 def opts @opts end |
Class Method Details
.key ⇒ Object
9 |
# File 'lib/cane/doc_check.rb', line 9 def self.key; :doc; end |
.name ⇒ Object
10 |
# File 'lib/cane/doc_check.rb', line 10 def self.name; "documentation checking"; end |
.options ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/cane/doc_check.rb', line 11 def self. { doc_glob: ['Glob to run doc checks over', default: '{app,lib}/**/*.rb', variable: 'GLOB', clobber: :no_doc], no_doc: ['Disable documentation checking', cast: ->(x) { !x }] } end |
Instance Method Details
#class_definition?(line) ⇒ Boolean
52 53 54 |
# File 'lib/cane/doc_check.rb', line 52 def class_definition?(line) line =~ /^\s*class\s+/ and $'.index('<<') != 0 end |
#comment?(line) ⇒ Boolean
56 57 58 |
# File 'lib/cane/doc_check.rb', line 56 def comment?(line) line =~ /^\s*#/ && !(MAGIC_COMMENT_REGEX =~ line) end |
#extract_class_name(line) ⇒ Object
60 61 62 |
# File 'lib/cane/doc_check.rb', line 60 def extract_class_name(line) line.match(/class ([^\s;]+)/)[1] end |
#file_names ⇒ Object
48 49 50 |
# File 'lib/cane/doc_check.rb', line 48 def file_names Dir[opts.fetch(:doc_glob)] end |
#find_violations(file_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cane/doc_check.rb', line 32 def find_violations(file_name) last_line = "" Cane::File.iterator(file_name).map.with_index do |line, number| result = if class_definition?(line) && !comment?(last_line) { file: file_name, line: number + 1, label: extract_class_name(line), description: "Classes are not documented" } end last_line = line result end.compact end |
#violations ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/cane/doc_check.rb', line 24 def violations return [] if opts[:no_doc] worker.map(file_names) {|file_name| find_violations(file_name) }.flatten end |
#worker ⇒ Object
64 65 66 |
# File 'lib/cane/doc_check.rb', line 64 def worker Cane.task_runner(opts) end |