Class: Git::Lint::Analyzers::CommitBodyPresence

Inherits:
Abstract
  • Object
show all
Defined in:
lib/git/lint/analyzers/commit_body_presence.rb

Constant Summary

Constants inherited from Abstract

Abstract::ISSUE_LINE_OFFSET, Abstract::LEVELS

Instance Attribute Summary

Attributes inherited from Abstract

#commit

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

build_issue_line, descendants, #enabled?, #error?, id, inherited, #initialize, #invalid?, label, #severity, #warning?

Constructor Details

This class inherits a constructor from Git::Lint::Analyzers::Abstract

Class Method Details

.defaultsObject



9
10
11
12
13
14
15
# File 'lib/git/lint/analyzers/commit_body_presence.rb', line 9

def self.defaults
  {
    enabled: true,
    severity: :warn,
    minimum: 1
  }
end

Instance Method Details

#issueObject



28
29
30
31
32
# File 'lib/git/lint/analyzers/commit_body_presence.rb', line 28

def issue
  return {} if valid?

  {hint: %(Use minimum of #{"line".pluralize count: minimum} (non-empty).)}
end

#minimumObject



24
25
26
# File 'lib/git/lint/analyzers/commit_body_presence.rb', line 24

def minimum
  settings.fetch :minimum
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/git/lint/analyzers/commit_body_presence.rb', line 17

def valid?
  return true if commit.fixup?

  valid_lines = commit.body_lines.reject { |line| line.match?(/^\s*$/) }
  valid_lines.size >= minimum
end