lint

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT

README

lint

Go Reference GitHub go.mod Go version Release

A configurable Go library that lints git branch names and commit messages against rules defined in YAML. Every rule carries its own severity level — critical, warning, or info — so you control how each violation is reported.

[!NOTE] The project is not a CLI tool — it is a Go library you can embed into any tool, including your own CLI or another Go project.

Features

  • Branch linting — validate branch names against a regex pattern and enforce the task/ticket ID format, e.g. feature/TASK-123.
  • Commit linting — validate the commit subject: allowed types, scope pattern, description length and task ID; and the commit body: length and mandatory body per commit type.
  • YAML-driven configuration — declare rules in a single lint.yml; every key is optional, and rules are strictly opt-in: an empty config reports no issues.
  • Per-rule severity — every rule is paired with an issue level: critical, warning, or info.
  • Programmatic configuration — build the same configuration in code with functional options, no YAML required.
  • Pure library — the linter never runs git commands itself: you pass in values built with github.com/gitamix/types, so it fits any workflow.

Installation

Run the command in terminal:

go get github.com/gitamix/lint
go get github.com/gitamix/types

The github.com/gitamix/types module provides the git domain types (Branch, Name, Commit, Message, …) consumed by the linters — you need it to construct the values you want to lint.

Getting started

Describe your rules in a gitamix.yml file. Every key is optional — only the rules you configure are enforced.

# Git branch rules.
branch:
  # task rules to enforce a specific format
  # for task identifiers in branch names.
  task:
    issue:
      # Level for task rules: critical, warning, info
      level: "info"
    # Regular expression pattern for the task identifier.
    pattern: (TASK|PROJ|BUG)-[0-9]+
  name:
    issue:
      # Level for branch name rules: critical, warning, info
      level: "warning"
    # Regular expression pattern for branch names.
    # This pattern allows only feature, bugfix and hotfix
    # branches with an uppercase task ID.
    pattern: ^(feature|bugfix|hotfix)/[A-Z]+-\d+

# Git commit rules.
commit:
  # Commit message rules, grouping subject and body configuration.
  message:
    # Subject rules (the first line of the commit message).
    subject:
      # Description rules for the subject text,
      # excluding the task identifier, type, and scope.
      description:
        # Length interval for the subject description text.
        length:
          issue:
            # Level for description length rules: critical, warning, info
            level: warning
          # Minimum number of characters allowed in the subject description.
          min: 10
          # Maximum number of characters allowed in the subject description.
          max: 72
      # Task integration rules for the commit subject.
      task:
        # Identifier rules for the task reference in the commit subject.
        id:
          issue:
            # Level for task id rules: critical, warning, info
            level: critical
          # Regular expression pattern for the task identifier.
          pattern: (TASK|PROJ|BUG)-[0-9]+
    # Body rules (the text after the subject, separated by a blank line).
    body:
      # Mandate rules: commit types for which the body is mandatory.
      mandate:
        # Commit types for which the body is mandatory.
        types:
          issue:
            # Level for body mandate rules: critical, warning, info
            level: critical
          # List of commit types that require a body.
          list:
            - fix
            - chore
            - refactor
            - perf
      # Length interval for the body text.
      length:
        issue:
          # Level for body length rules: critical, warning, info
          level: info
        # Minimum number of characters allowed in the body.
        min: 10
        # Maximum number of characters allowed in the body.
        max: 255
  # Scope rules for the commit subject
  # (the part in parentheses after the type).
  scope:
    issue:
      # Level for scope rules: critical, warning, info
      level: warning
    # Regular expression pattern for the commit scope.
    pattern: ^[A-Za-z _-]+$
  # Allowed commit types (e.g. feat, fix, chore).
  types:
    issue:
      # Level for commit type rules: critical, warning, info
      level: critical
    # List of allowed commit types.
    list:
      - feat
      - fix
      - chore
      - refactor
      - perf
      - test
      - docs

Load the config and lint branches and commits:

package main

import (
    "fmt"
    "log"

    typesbranch "github.com/gitamix/types/branch"
    typescommit "github.com/gitamix/types/commit"

    "github.com/gitamix/lint/branch"
    "github.com/gitamix/lint/commit"
    "github.com/gitamix/lint/config"
)

func main() {
    cfg, err := config.Load("path/to/gitamix.yml")
    if err != nil {
        log.Fatal(err)
    }
    brs := branch.NewBranch(
        typesbranch.NewBranch(typesbranch.NewName("release/TASK-123")),
        cfg.Branch(),
    )
    for _, iss := range brs.Issues() {
        fmt.Println(iss.Type(), iss.Message()) 
    }
    cmts := commit.NewCommits(
        []typescommit.Commit{
            typescommit.NewCommit(
                typescommit.NewHash("abc1234567"),
                typescommit.ParseMessage([]byte("[TASK-123] fix: tiny fix\n")),
            ),
        },
        cfg.Commit(),
    )
    for _, iss := range cmts.Issues() {
        fmt.Println(iss.Type(), iss.Message())
    }
}

Output:

warning branch name 'release/TASK-123' doesn't match the required pattern '^(feature|bugfix|hotfix)/[A-Z]+-\d+'
warning abc1234: scope not found in subject by expression '^[A-Za-z _-]+$'
warning abc1234: subject description length is not in range [10-72]
critical abc1234: body is required for type 'fix'
Rules reference
YAML path Rule Default level
branch.name Branch name matches pattern — set level explicitly
branch.task Branch name contains a task ID matching pattern critical
commit.types Commit type is one of list critical
commit.scope Commit scope matches pattern warning
commit.message.subject.description.length Subject description length is within [min, max] (inclusive) warning
commit.message.subject.task.id Subject contains a task ID matching pattern critical
commit.message.body.length Body length is within [min, max] (inclusive) — set level explicitly
commit.message.body.mandate.types Body is required for the commit types in list always critical

When a rule is configured but level is omitted, the default level from the table applies. Rules without a default report with an unspecified level, so set level explicitly for them.

Documentation

Full API reference is available on pkg.go.dev

Requirements

The library does not run git commands itself. Obtain branch names and commit messages in your own workflow (for example, with git branch and git log), wrap them into github.com/gitamix/types values, and pass them to the linters.

Contributing

Want to contribute? Read CONTRIBUTING.md for the full workflow, repository requirements, and Pull Request process.

Please open an issue to discuss large or breaking changes before implementing.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Author / Contact

Maintained by Ilya Sitnikov

Directories

Path Synopsis
Package branch provides a linter for validating a git branch against the rules defined in the lint configuration.
Package branch provides a linter for validating a git branch against the rules defined in the lint configuration.
name
Package name provides a linter for validating commit branch names.
Package name provides a linter for validating commit branch names.
Package commit provides linters that validate git commit messages against the configured rules by aggregating issues from sub-linters.
Package commit provides linters that validate git commit messages against the configured rules by aggregating issues from sub-linters.
message
Package message provides a linter that validates a complete commit message by aggregating issues from its task, subject, and body sub-linters.
Package message provides a linter that validates a complete commit message by aggregating issues from its task, subject, and body sub-linters.
message/body
Package body provides a linter that validates the commit message body against the configured length interval.
Package body provides a linter that validates the commit message body against the configured length interval.
message/subject
Package subject provides a linter that validates a commit message subject by aggregating issues from its type, scope, and description sub-linters.
Package subject provides a linter that validates a commit message subject by aggregating issues from its type, scope, and description sub-linters.
message/subject/description
Package description provides a linter that validates the length of the commit message subject description against the configured interval.
Package description provides a linter that validates the length of the commit message subject description against the configured interval.
message/task
Package task provides a linter that validates the task identifier in a commit message against the configured pattern.
Package task provides a linter that validates the task identifier in a commit message against the configured pattern.
scope
Package scope provides a linter for validating commit scope against the configured pattern.
Package scope provides a linter for validating commit scope against the configured pattern.
types
Package types provides a linter for validating commit types against the configured allowed types.
Package types provides a linter for validating commit types against the configured allowed types.
Package config provides types and functions for working with lint configuration.
Package config provides types and functions for working with lint configuration.
branch
Package branch provides types and functions for working with commit branch configuration.
Package branch provides types and functions for working with commit branch configuration.
branch/defaults
Package defaults provides types and functions to work with configuration of the default branch.
Package defaults provides types and functions to work with configuration of the default branch.
branch/name
Package name provides types and functionality to work with configuration of branch names.
Package name provides types and functionality to work with configuration of branch names.
commit
Package commit provides configuration types for the commit message portion of a git lint run.
Package commit provides configuration types for the commit message portion of a git lint run.
commit/message
Package message provides configuration types for the commit message portion of a git branch lint run, grouping the subject and body configurations and the functional options to build the message config.
Package message provides configuration types for the commit message portion of a git branch lint run, grouping the subject and body configurations and the functional options to build the message config.
commit/message/body
Package body provides the configuration of the commit message body, including its length interval and the functional options to build the config.
Package body provides the configuration of the commit message body, including its length interval and the functional options to build the config.
commit/message/body/mandate
Package mandate configures the set of commit types for which the commit message body is mandatory.
Package mandate configures the set of commit types for which the commit message body is mandatory.
commit/message/subject
Package subject provides the configuration of the commit message subject, including its description and task integration, and the functional options to build the config.
Package subject provides the configuration of the commit message subject, including its description and task integration, and the functional options to build the config.
commit/message/subject/description
Package description provides the configuration of the commit message subject description, including its length interval and the functional options to build the config.
Package description provides the configuration of the commit message subject description, including its length interval and the functional options to build the config.
commit/scope
Package scope provides the configuration of the commit message subject scope.
Package scope provides the configuration of the commit message subject scope.
commit/types
Package types provides the configuration of the commit types allowed during a git lint run.
Package types provides the configuration of the commit types allowed during a git lint run.
task
Package task provides types and functions for working with task (issue) configuration.
Package task provides types and functions for working with task (issue) configuration.
task/id
Package id provides types and functions for working with task (issue) identifier configuration.
Package id provides types and functions for working with task (issue) identifier configuration.
value
Package value provides types and functionality to work with config values.
Package value provides types and functionality to work with config values.
Package errs provides error definitions to be used across the all packages of the project.
Package errs provides error definitions to be used across the all packages of the project.
internal
marshalling/config/branch
Package branch provides the transport structures used to unmarshal the commit branch configuration from config files.
Package branch provides the transport structures used to unmarshal the commit branch configuration from config files.
marshalling/config/branch/defaults
Package defaults provides the transport structures used to unmarshal the default branch configuration from config files.
Package defaults provides the transport structures used to unmarshal the default branch configuration from config files.
marshalling/config/commit
Package commit provides the transport structures used to unmarshal the commit configuration from config files.
Package commit provides the transport structures used to unmarshal the commit configuration from config files.
marshalling/config/commit/message
Package message provides the transport structures used to unmarshal the commit message configuration from config files.
Package message provides the transport structures used to unmarshal the commit message configuration from config files.
marshalling/config/commit/message/body
Package body provides the transport structures used to unmarshal the commit message body configuration from config files.
Package body provides the transport structures used to unmarshal the commit message body configuration from config files.
marshalling/config/commit/message/body/mandate
Package mandate provides the transport structures used to unmarshal the commit message body mandate configuration from config files, describing the commit types for which the commit message body is mandatory.
Package mandate provides the transport structures used to unmarshal the commit message body mandate configuration from config files, describing the commit types for which the commit message body is mandatory.
marshalling/config/commit/message/subject
Package subject provides the transport structures used to unmarshal the commit message subject configuration from config files.
Package subject provides the transport structures used to unmarshal the commit message subject configuration from config files.
marshalling/config/commit/message/subject/description
Package description provides the transport structures used to unmarshal the commit message subject description configuration from config files.
Package description provides the transport structures used to unmarshal the commit message subject description configuration from config files.
marshalling/config/task
Package task provides the transport structures used to unmarshal the task (issue) configuration from config files.
Package task provides the transport structures used to unmarshal the task (issue) configuration from config files.
marshalling/config/value
Package value provides the transport structures used to unmarshal the config value types like string patterns, integer ranges, etc.
Package value provides the transport structures used to unmarshal the config value types like string patterns, integer ranges, etc.
Package issue provides types to describe issues in linting reports.
Package issue provides types to describe issues in linting reports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL