Detalhes do pacote

conventional-changelog-lint

marionebl12.9kMITdepreciado2.1.1

renamed to commitlint: https://git.io/vQ1rU

Lint commit messages against a conventional-changelog preset and ruleset

conventional, conventional-changelog, log, changelog

readme (leia-me)

Lint commit messages

conventional-changelog-lint stability

npm version Travis branch AppVeyor branch

  • 🚓 Enforce commit conventions
  • 🤖 Plays nice with conventional-changelog
  • 📦 Supports shareable configuration

Installation

Fetch it with npm

npm install --save-dev conventional-changelog-lint

Usage

conventional-changelog-lint provides a command line and node interface.

CLI

conventional-changelog-lint demo

The command line interface reads .conventional-changelog-lintrc resolves extends configurations.

❯ conventional-changelog-lint --help
  conventional-changelog-lint - Lint commit messages against a conventional-changelog preset and ruleset

  [input] reads from stdin if --edit, --from, --to are omitted
  --color,-c    toggle formatted output, defaults to: true
  --edit,-e     read last commit message found in ./git/COMMIT_EDITMSG
  --extends,-x  array of shareable configurations to extend
  --from,-f     lower end of the commit range to lint; applies if edit=false
  --preset,-p   conventional-changelog-preset to use for commit message parsing, defaults to: angular
  --to,-t       upper end of the commit range to lint; applies if edit=false
  --quiet,-q    toggle console output

Recipes

git hook

As a commitmsg git-hook with "husky"

  {
    "scripts": {
      "commitmsg": "conventional-changelog-lint -e"
    }
  }

Last commit

As part of npm test

  {
    "scripts": {
      "test": "conventional-changelog-lint --from=HEAD~1"
    }
  }

Lint all commits in Pull Request

You can lint all commits in a PR by passing all commits that are present in SOURCE_BRANCH but unavailable in BASE_BRANCH:

conventional-changelog-lint --from=BASE_BRANCH to=SOURCE_BRANCH

Most of the time BASE_BRANCH will be master for Github Flow.

This assumes SOURCE_BRANCH is available on your local checkout. This is not true by default for all PRs originating from clones of a repository.

Given you'd like to lint all commits in PR origination from branch remote-test on the repository github.com/other-name/test targeting master on github.com/your-name/test:

cd test # make sure CWD is in your repository
git remote add other-name https://github.com/other-name/test.git
git fetch other-name

conventional-changelog-lint --from=master --to=other-name/test

See scripts/lint:commit.sh for an example on how to obtain SOURCE_BRANCH from a Github clone automatically on Travis.

Travis

Commit Linting on CI has to handle the following cases

  • Direct commits
  • Branch Pull Requests
  • Fork Pull Requests

An exemplary implementation is provided as bash script working on Travis CI.

# Force full git checkout
before_install: git fetch --unshallow

script:
  - ./scripts/lint:commit.sh # [1] scripts/lint:commit.sh

[1]: See scripts/lint:commit.sh for reference

API

The programming interface does not read configuration by default, it has to be provided as second parameter.

import lint from 'conventional-changelog-lint';
const report = lint(
  'docs: add node api interface usage',
  {
    preset: {},
    configuration: {}
  }
);

To achieve the same behavior as with the command line interface you can use the provided utility functions:

import lint from 'conventional-changelog-lint';
import {
  getPreset,
  getConfiguration
} from 'conventional-changelog-lint';

const report = lint(
  'docs: add node api interface usage',
  {
    preset: await getPreset('angular'),
    configuration: await readConfiguration('conventional-changelog-lint')
  }
);

Configuration

conventional-changelog-lint is configured via .conventional-changelog-lintrc and shareable configuration.

When no .conventional-changelog-lintrc is found it will use the angular shareable config. See the documentation there for default rules.

When a .conventional-changelog-lintrc is found it will not load any preset unless specified via extends configuration.

extends

{
  "extends": ["angular"]
}

Array of shareable configurations to extend. Configurations are resolved as conventional-changelog-lint-config-${name} and have to be installed. See npm search for available shareable configurations.


⇨ See shareable-config for details

preset

{
  "preset": "angular"
}

conventional-changelog preset name to use for parsing of commit messages.


⇨ See conventional-changelog for details

rules

{
  "rules": {
    "body-leading-blank": [1, "always"],
    "header-max-length": [1, "always", 72],
    "subject-full-stop": [1, "never", "."]
  }
}

Rules applicable to the linted commit messages. By default all rules are turned off via a level of 0. They can be enabled by shareable configuration, such as the angular config, which is loaded by default.


⇨ See rules for details

wildcards

Patterns to exclude from linting

wildcards: {
  merge: [
    '/^(Merge pull request)|(Merge (.*?) into (.*?)$)/'
  ],
  release: [
    '/^\\d.\\d.\\d$/'
  ],
  revert: [
    '/^revert: (.*)/'
  ]
}

Shallow clones

TL;DR

Perform git fetch --shallow before linting.

Most likely you are reading this because you where presented with an error message:

  'Could not get git history from shallow clone.
  Use git fetch --shallow before linting.
  Original issue: https://git.io/vyKMq\n Refer to https://git.io/vyKMv for details.'

Explanation

git supports checking out shallow clones of a repository to save bandwith in times. These limited copies do not contain a full git history. This makes conventional-changelog-lint fail, especially when running on large commit ranges. To ensure linting works every time you should convert a shallow git repo to a complete one. Use git fetch --shallow to do so.

Travis

Ensure full git checkouts on TravisCI, add to .travis.yml:

before_install:
  - git fetch --unshallow

Appveyor

Ensure full git checkouts on AppVeyor, add to appveyor.yml:

shallow_clone: false

Supported Node.js versions

conventional-changelog-lint supports the active Node.js LTS version and higher: >= 4

Related projects


Copyright 2016 by Mario Nebl and contributors. Released under the MIT license.

changelog (log de mudanças)

2.1.1 (2017-07-10)

2.1.0 (2017-07-07)

Bug Fixes

  • prevent false positives for footer-leading-blank (#33) (05b4427)
  • rebuff rules (#34) (702a2f7)
  • throw when detecting a shallow clone (8c354c5), closes #7 #12
  • update to latest angular config (b1f3606)

Features

2.0.0 (2017-07-07)

Documentation

  • add recipe for linting of all commits in a PR (#36) (1e69d54), closes #35

Bug Fixes

BREAKING CHANGES :warning:

  • wildcards config is now ignored entirely

1.1.9 (2017-04-05)

Bug Fixes

  • rules: export subject-min-length rule (29d149e)
  • override arrays when merging user configuration (8637292), closes #11

1.1.8 (2017-03-31)

1.1.7 (2017-03-12)

Bug Fixes

  • move mz to dependencies (3b3f057)

1.1.6 (2017-03-12)

Bug Fixes

  • add missing globby dependency (4e71f84)

1.1.5 (2017-03-12)

1.1.4 (2017-03-12)

Bug Fixes

  • move git-toplevel to dependencies (d036390)

1.1.3 (2017-03-12)

Bug Fixes

  • determine git toplevel before reading .git/COMMIT_EDITMSG (c45a62b)

1.1.2 (2017-03-10)

Bug Fixes

  • allow empty scopes in scope-enum check (b433c07)

1.1.1 (2017-03-03)

1.1.0 (2016-11-01)

Features

1.0.1 (2016-08-15)

Bug Fixes

  • rules: respect keyword setting for scope-empty (#11) (c646a60), closes #10

1.0.0 (2016-06-20)

Bug Fixes

  • cli: disable angular defaults when a rc file is provided (ef9a2b7)

Features

  • rules: update to latest default ruleset (1c2f772)

BREAKING CHANGES

  • rules: fix: remove revert type
  • fix: add perf type
  • fix: allow multidigit release versions
  • feat: warn on footer-leading-blank

0.3.4 (2016-04-15)

Bug Fixes

  • cli: disable angular defaults when a rc file is provided (8c3ee6c)

0.3.2 (2016-03-03)

Bug Fixes

  • execute dynamic configuration in get-configuration (ecb041e)

0.3.1 (2016-02-25)

Bug Fixes

  • guard pos lexer against errors (a12f1b2)

0.3.0 (2016-02-25)

Features

  • add footer rules (6acb930)
  • add subject-leading-capital rule (c6714a4)
  • rules: add rules for tense-checking (d7b8d4b)

0.2.0 (2016-02-25)

Bug Fixes

  • catch unhandled rejections (b7e4bf9)

Features

  • support for dynamic and async rules (efce01a)

0.1.10 (2016-02-24)

Bug Fixes

  • skip language check if no lang is detected (d3e8454)

0.1.9 (2016-02-22)

Bug Fixes

  • use raw commit message to check for leading blank line (9c1ca3b)

0.1.8 (2016-02-22)

0.1.7 (2016-02-14)

Bug Fixes

  • prune duplicate dependency (33a6fca)

0.1.6 (2016-02-14)

0.1.5 (2016-02-14)

Bug Fixes

0.1.4 (2016-02-14)

Bug Fixes

0.1.3 (2016-02-14)

Bug Fixes

0.1.2 (2016-02-14)

Bug Fixes

  • enforce addition of distribution folder (cbe3a90)

0.1.1 (2016-02-14)

Bug Fixes

  • rebuild before releases (763bf53)

0.1.0 (2016-02-14)

Bug Fixes

  • be less strict with matched languages (dae11d1)
  • handle precedence and defaults correctly (a8b980a)

Features


Copyright 2016 by Mario Nebl and contributors. Released under the MIT license.