Class: Git::Lint::Analyzers::CommitBodyParagraphNewLine

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

Overview

Analyzes proper capitalization of commit body paragraphs.

Constant Summary collapse

PATTERNS =
{
  general: /
    \n      # New line.
    (?!     # Negative lookahead start.
    \s{1,}  # Indentation.
    )       # Negative lookahead end.
  /mx,
  markup: /
    \A       # Start of line.
    (        # Start of conditional.
    \s*\#    # Optional whitepace with comment.
    |        # Or.
    `        # Backtick.
    |        # Or.
    -        # Dash.
    |        # Or.
    _        # Underscore.
    |        # Or.
    \+       # Plus.
    |        # Or.
    \d+\.    # Ordered list item.
    |        # Or.
    \.       # Unordered list itme.
    |        # Or.
    \*       # Unordered list itme.
    |        # Or.
    \[.*?\]  # ASCII Doc code block.
    )        # End of conditional.
  /x
}.freeze

Constants inherited from Abstract

Abstract::BODY_OFFSET, Abstract::LEVELS

Instance Attribute Summary

Attributes inherited from Abstract

#commit

Instance Method Summary collapse

Methods inherited from Abstract

build_issue_line, #error?, id, #invalid?, label, #severity, #warning?

Constructor Details

#initialize(commit, patterns: PATTERNS) ⇒ CommitBodyParagraphNewLine

Returns a new instance of CommitBodyParagraphNewLine.



39
40
41
42
# File 'lib/git/lint/analyzers/commit_body_paragraph_new_line.rb', line 39

def initialize(commit, patterns: PATTERNS, **)
  super(commit, **)
  @patterns = patterns
end

Instance Method Details

#issueObject



46
47
48
49
50
51
52
53
# File 'lib/git/lint/analyzers/commit_body_paragraph_new_line.rb', line 46

def issue
  return {} if valid?

  {
    hint: "Avoid unnecessary new lines.",
    lines: affected_lines
  }
end

#valid?Boolean

Returns:

  • (Boolean)


44
# File 'lib/git/lint/analyzers/commit_body_paragraph_new_line.rb', line 44

def valid? = invalids.empty?