Gitlint Core

0.19.1 · active · verified Sat Apr 11

Gitlint-core is the core library for Gitlint, a Python-based linter that enforces style and consistency for Git commit messages. It is an actively maintained project with regular releases, providing robust checks and customizability for commit hooks and CI pipelines.

Warnings

Install

Imports

Quickstart

Demonstrates how to programmatically lint a commit message string using `gitlint-core`. It initializes a `GitlintConfig` and `Gitlint` instance, then passes a commit message string to the `lint` method. Violations are returned as a list of `RuleViolation` objects.

from gitlint.gitlint import Gitlint
from gitlint.options import GitlintConfig
from gitlint.display import Display

commit_message = (
    "feat: Add new feature\n\n"  # Title
    "This commit introduces a brand new feature to the application.\n\n"
    "It includes several improvements and bug fixes related to the new functionality."
)

# Initialize GitlintConfig (can be customized, or defaults are used)
config = GitlintConfig()
# You can set options programmatically, e.g., config.max_line_length = 100

# Initialize Gitlint with a display (e.g., to print to stdout)
display = Display(config)
gitlint = Gitlint(config, display)

# Lint the commit message
violations = gitlint.lint(commit_msg_str=commit_message)

if violations:
    print(f"Found {len(violations)} violations:")
    for violation in violations:
        print(f"- {violation.rule_id}: {violation.message} (line {violation.line_nr})")
else:
    print("Commit message is valid!")

view raw JSON →