View Source Commitlint (commitlint v0.1.2)

Commitlint

This project is an implementation of the Conventional commits specification. This is inspired by the JS library pendant commitlint. The hook installation was inspired by elixir-pre-commit

installation

Installation

If available in Hex, the package can be installed by adding commitlint to your list of dependencies in mix.exs:

def deps do
  [
    {:commitlint, "~> 0.1.2", runtime: false, only: :dev}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/commitlint.

configuration

Configuration

The configuration is done in the config/config.exs file. The default configuration is:

config :commitlint,
  allowed_types: [
    "feat",
    "fix",
    "docs",
    "style",
    "refactor",
    "perf",
    "test",
    "build",
    "ci",
    "chore",
    "revert"
  ]

usage

Usage

The package provides a mix task commit_lint. If you want to try it out, you can run:

echo "feat: add commit linting" | mix commit_lint  # Should have exit error 0
echo "unknown: add commit linting" | mix commit_lint  # Should have exit error 1

Upon compilation, the package will install a commit-msg hook in the .git/hooks directory. This will take care of running the commit linting on every commit.

contributing

Contributing

If you want to contribute, you are welcome to posting issues and PRs, just make sure to follow the Conventional commits standard.

local-development

Local development

First fork the repository, clone your fork, install the dependencies and compile everything:

git clone <your fork>
cd elixir-commitlint
mix deps.get
mix compile

To ensure that your commits are following the conventional commits, you can use, well, commitlint :)

cp priv/commit-msg .git/hooks/commit-msg && chmod +x .git/hooks/commit-msg

Use the following to run the test cases:

mix test

license

License

See LICENSE for details.

Link to this section Summary

Functions

Lint the commit message.

Link to this section Types

@type lint_result() :: :ok | {:error, String.t()}

Link to this section Functions

@spec lint!(String.t()) :: :ok

Lint the commit message.

examples

Examples

iex> Commitlint.lint!("feat: add linting to commit messages")
:ok

iex> Commitlint.lint!("inexistent: add a test commit")
** (Commitlint.LintException) Invalid commit type: inexistent