class Pronto::Docslint

Constants

CONFIG_FILE
CONFIG_KEYS

Attributes

additions_treshold[R]
deletions_treshold[R]
watched_file_extensions[R]

Public Instance Methods

run() click to toggle source
# File lib/pronto/docslint.rb, line 11
def run
  return [] if no_patches? || documentation_exists?

  prepare_config
  meaningful_patches.map { |patch| new_message(patch) }.compact
end

Private Instance Methods

documentation_exists?() click to toggle source
# File lib/pronto/docslint.rb, line 24
def documentation_exists?
  @patches.any? { |patch| patch.delta.new_file[:path].match?(/\.md$/) }
end
fill_empty_settings_with_default_values() click to toggle source
# File lib/pronto/docslint.rb, line 61
def fill_empty_settings_with_default_values
  @watched_file_extensions ||= %w[js rb]
  @additions_treshold ||= 1
  @deletions_treshold ||= 1
end
git_repo_path() click to toggle source
# File lib/pronto/docslint.rb, line 67
def git_repo_path
  @git_repo_path ||= Rugged::Repository.discover(File.expand_path(Dir.pwd)).workdir
end
meaningful_patches() click to toggle source
# File lib/pronto/docslint.rb, line 28
def meaningful_patches
  extentions = /^app\/.*\.(#{watched_file_extensions.join('|')})$/
  @patches
    .select { |patch| !patch.delta.deleted? }
    .select { |patch| patch.additions > additions_treshold || patch.deletions > deletions_treshold }
    .select { |patch| patch.delta.new_file[:path].match?(extentions) }
end
new_message(patch) click to toggle source
# File lib/pronto/docslint.rb, line 36
def new_message(patch)
  path = patch.delta.new_file[:path]
  watched_extensions = watched_file_extensions.map { |ext| "`#{ext}`" }.join(',')
  offence = "Changes on #{watched_extensions} files requires documentation changes.."
  line = patch.added_lines.first || patch.deleted_lines.first
  Message.new(path, line, :warning, offence, nil, self.class)
end
no_patches?() click to toggle source
# File lib/pronto/docslint.rb, line 20
def no_patches?
  !@patches || @patches.count.zero?
end
prepare_config() click to toggle source
# File lib/pronto/docslint.rb, line 44
def prepare_config
  read_config
  fill_empty_settings_with_default_values
end
read_config() click to toggle source
# File lib/pronto/docslint.rb, line 49
def read_config
  config_file = File.join(git_repo_path, CONFIG_FILE)
  return unless File.exist?(config_file)

  config = YAML.load_file(config_file)

  CONFIG_KEYS.each do |config_key|
    next unless config[config_key]
    instance_variable_set("@#{config_key}", config[config_key])
  end
end