class Danger::DangerJazzy

This is a danger plugin to check for undocumented symbols via Jazzy.

@example Fail on undocumented symbols in modified files.

jazzy.check

@example Fail on undocumented symbols in all files.

jazzy.check fail: :all

@example Warn about undocumented symbols in modified files.

jazzy.check warn: :modified

@example Write a custom message for undocumented symbols in modified files.

jazzy.undocumented.each do |item|
    message "You forgot to document this", file:item.file, line:item.line
end

@example Write a custom message for undocumented symbols in all files.

jazzy.undocumented(:all).each do |item|
    message "You forgot to document this", file:item.file, line:item.line
end

@see fwal/danger-jazzy @tags jazzy, docs, documentation

Constants

DEFAULT_INLINE_MESSAGE
DEFAULT_MESSAGE

Attributes

ignore[RW]

List of files to ignore, defaults to []. @return [[String]]

inline_message[RW]

Message to display inline, defaults to 'Undocumented symbol `%<symbol>s`'. @return [String]

message[RW]

Message to display, defaults to 'Undocumented symbol `%<symbol>s` in *%<file>s*'. @return [String]

path[RW]

Path to the docs folder, defaults to 'docs/'. @return [String]

Public Instance Methods

check(config = {}) click to toggle source

Checks files for modified symbols.

Takes a hash with the following keys:

* `fail`
* `warn`

Available scopes:

* `modified`
* `all`

@param [Hash] config @return [void]

# File lib/jazzy/plugin.rb, line 66
def check(config = {})
  @config = config
  fail_check
  warn_check
end
undocumented(scope = :modified) click to toggle source

Returns a list of undocumented symbols in the current diff.

Available scopes:

* `modified`
* `all`

@param [Key] scope @return [Array of symbol]

# File lib/jazzy/plugin.rb, line 81
def undocumented(scope = :modified)
  return [] unless scope != :ignore && File.exist?(undocumented_path)
  @undocumented = { modified: [], all: [] } if @undocumented.nil?
  load_undocumented(scope) if @undocumented[scope].empty?
  @undocumented[scope]
end

Private Instance Methods

docs_path() click to toggle source
# File lib/jazzy/plugin.rb, line 90
def docs_path
  @path || 'docs/'
end
fail_check() click to toggle source
# File lib/jazzy/plugin.rb, line 135
def fail_check
  undocumented(fail_scope).each do |item|
    # rubocop:disable Style/SignalException, Style/GuardClause
    if item.file.nil? || item.line.nil?
      fail message_template % item.to_h
    else
      fail inline_message_template % item.to_h, file: item.file, line: item.line
    end
    # rubocop:enable Style/SignalException, Style/GuardClause
  end
end
fail_scope() click to toggle source
# File lib/jazzy/plugin.rb, line 127
def fail_scope
  @config[:fail] || :modified
end
files_of_interest() click to toggle source
# File lib/jazzy/plugin.rb, line 110
def files_of_interest
  git.modified_files + git.added_files
end
ignored_files() click to toggle source
# File lib/jazzy/plugin.rb, line 94
def ignored_files
  @ignore || []
end
inline_message_template() click to toggle source
# File lib/jazzy/plugin.rb, line 102
def inline_message_template
  @inline_message || DEFAULT_INLINE_MESSAGE
end
load_undocumented(scope) click to toggle source
# File lib/jazzy/plugin.rb, line 114
def load_undocumented(scope)
  reader = UndocumentedReader.new(undocumented_path)
  @undocumented[scope] = reader.undocumented_symbols.select do |item|
    next unless !item.nil? && item.file
    next if ignored_files.include? item.file
    if scope == :modified
      files_of_interest.include?(item.file)
    else
      true
    end
  end
end
message_template() click to toggle source
# File lib/jazzy/plugin.rb, line 98
def message_template
  @message || DEFAULT_MESSAGE
end
undocumented_path() click to toggle source
# File lib/jazzy/plugin.rb, line 106
def undocumented_path
  File.join(docs_path, 'undocumented.json')
end
warn_check() click to toggle source
# File lib/jazzy/plugin.rb, line 147
def warn_check
  undocumented(warn_scope).each do |item|
    if item.file.nil? || item.line.nil?
      warn message_template % item.to_h
    else
      warn inline_message_template % item.to_h, file: item.file, line: item.line
    end
  end
end
warn_scope() click to toggle source
# File lib/jazzy/plugin.rb, line 131
def warn_scope
  @config[:warn] || :ignore
end