NAME

Git::Lint::Check::Commit - parent module for commit check modules

SYNOPSIS

use parent 'Git::Lint::Check::Commit';

# inside of the child module, check method
sub check {
    my $self  = shift;
    my $input = shift;

    my $match = sub {
        my $line = shift;
        return 1 if $line =~ /\s$/;
        return;
    };

    my @issues = $self->parse(
        input => $input,
        match => $match,
        check => $check_name
    );

    return @issues;
}

DESCRIPTION

Git::Lint::Check::Commit provides methods for Git::Lint commit check modules.

This module is not meant to be initialized directly.

ADDING CHECK MODULES

To add check functionality to Git::Lint, additional check modules can be created as child modules to Git::Lint::Check::Commit.

For an example to start creating commit check modules, see Git::Lint::Check::Commit::Whitespace or any message check module released within this distribution.

CHECK MODULE REQUIREMENTS

Child modules must implement the check method which gathers, formats, and returns a list of issues.

The methods within this module can be used to parse and report the issues in the expected format, but are not required to be used.

The issues returned from commit check modules must be a list of hash refs each with filename and message keys and values.

my @issues = (
    {
      'filename' => 'catalog.txt',
      'message' => 'trailing whitespace (line 1)',
    },
    {
      'filename' => 'catalog.txt',
      'message' => 'trailing whitespace (line 2)',
    },
);

CONSTRUCTOR

new

This method is inherited from Git::Lint::Check.

METHODS

diff

Gathers, parses, and returns the commit diff.

ARGUMENTS

None.

RETURNS

An array ref of the diff of the commit.

format_issue

Formats the match information into the expected issue format.

ARGUMENTS

filename

The name of the file from the commit diff.

check

The check name or message to format.

lineno

The line number being checked.

RETURNS

A hash ref with filename and message key and value.

get_filename

Parses the filename out of a single line of git diff output.

ARGUMENTS

None.

The git diff line to be checked for filename is passed as unnamed input.

RETURNS

The filename, if found.

parse

Parses the diff input for violations using the match subref check.

ARGUMENTS

input

Array ref of the commit diff input to check.

match

Code ref (sub reference) containing the check logic.

check

The check name or message to use for reporting issues.

RETURNS

A list of hashrefs of formatted issues.