/commitlint-config

Shareable commitlint config enforcing conventional commit

Primary LanguageTypeScriptBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

commitlint-config

github release npm codecov module type: cjs+esm license conventional commits typescript vitest yarn

Shareable commitlint config enforcing conventional commits

Contents

What is this?

This package exports a shareable commitlint configuration that enforces conventional commits.

It also includes a set of utilities for customizing rules.

When should I use this?

This package can be used with @commitlint/cli and @commitlint/prompt-cli.

Commit parsing options can also be used with conventional-changelog and conventional-commits-parser.

Install

yarn add -D @flex-development/commitlint-config @commitlint/cli

From Git:

yarn add -D @flex-development/commitlint-config@flex-development/commitlint-config @commitlint/cli
See Git - Protocols | Yarn  for details on requesting a specific branch, commit, or tag.

Use

echo '{\n  "extends": "@flex-development"\n}' > .commitlintrc.json
commitlint --from HEAD~1 --to HEAD --verbose

Customizing scopes and types

Due to an unresolved commitlint issue, extended commitlint configurations do not concatenate scope-enum, nor type-enum. Follow the example below to customize commit scopes and types losslessly.

touch .commitlintrc.cts
/**
 * @file Configuration - commitlint
 * @module config/commitlint
 * @see https://commitlint.js.org
 */

import {
  RuleConfigSeverity as Severity,
  type UserConfig
} from '@commitlint/types'
import { scopes } from '@flex-development/commitlint-config'

/**
 * `commitlint` configuration object.
 *
 * @const {UserConfig} config
 */
const config: UserConfig = {
  extends: ['@flex-development'],
  rules: {
    'scope-enum': [Severity.Error, 'always', scopes(['bundle', 'transpile'])]
  }
}

export default config

You may need to set TS_NODE_PROJECT if running commitlint from the command line.

See docs/examples/commitlint.config.cjs for an example config written in pure CommonJS.

Rules

Rules not documented below are disabled by default. Consult the rules reference for a list of all rules.

Problems

The following rules are considered problems for @flex-development/commitlint-config and will yield a non-zero exit code when not met.

body-full-stop

  • condition: body ends with value

  • rule: never

  • value:

    '.'

body-leading-blank

  • condition: body begins with blank line
  • rule: always

body-max-length

  • condition: body has value or less characters

  • rule: always

  • value:

    Number.MAX_SAFE_INTEGER

body-max-line-length

  • condition: body lines has value or less characters

  • rule: always

  • value:

    2050

footer-leading-blank

  • condition: footer begins with blank line
  • rule: always

footer-max-length

  • condition: footer has value or less characters

  • rule: always

  • value:

    Number.MAX_SAFE_INTEGER

footer-max-line-length

  • condition: footer lines has value or less characters

  • rule: always

  • value:

    2050

header-full-stop

  • condition: header ends with value

  • rule: never

  • value:

    '.'

header-max-length

  • condition: header has value or less characters

  • rule: always

  • value:

    100

scope-case

  • condition: scope is in case that is in value

  • rule: always

  • value:

    ['kebab-case', 'lower-case']

scope-enum

  • condition: scope is found in value

  • rule: always

  • value:

    scopes()

scope-max-length

  • condition: scope has value or less characters

  • rule: always

  • value:

    max(scopes())

scope-min-length

  • condition: scope has value or more characters

  • rule: always

  • value:

    min(scopes())

subject-empty

  • condition: subject is empty
  • rule: never

subject-full-stop

  • condition: subject ends with value

  • rule: never

  • value:

    '.'

subject-min-length

  • condition: subject has value or more characters

  • rule: always

  • value:

    2

trailer-exists

  • condition: message has trailer value

  • rule: always

  • value:

    'Signed-off-by:'

type-case

  • description: type is in case value

  • rule: always

  • value:

    'lower-case'

type-empty

  • condition: type is empty
  • rule: never

type-enum

  • condition: type is found in value

  • rule: always

  • value:

    types()

type-max-length

  • condition: type has value or less characters

  • rule: always

  • value:

    max(types)

type-min-length

  • condition: type has value or more characters

  • rule: always

  • value:

    min(types())

API

This package exports the following identifiers:

The default export is config.

config

commitlint configuration object.

Properties:

  • defaultIgnores
  • formatter
  • helpUrl
  • ignores
  • parserPreset
  • plugins
  • prompt
  • rules

See the configuration reference for more details.

Utilities

max(array)

Returns the length of the longest string in the given array.

Parameters
  • {string[]} array — Array to evaluate
Returns

{number} Length of longest string in array.

Source

src/utils/max.ts

min(array)

Returns the length of the shortest string in the given array.

Parameters
  • {string[]} array — Array to evaluate
Returns

{number} Length of shortest string in array.

Source

src/utils/min.ts

scopes([extras])

Returns an array containing valid commit scopes.

Parameters
  • {(Set<string> | string[])?} [extras=[]] — Additional commit scopes
Returns

{LiteralUnion<Scope, string>[]} Commit scopes array.

Source

src/utils/scopes.ts

types([extras])

Returns an array containing valid commit types.

Parameters
  • {(Set<string> | string[])?} [extras=[]] — Additional commit types
Returns

{LiteralUnion<Type, string>[]} Commit types array.

Source

src/utils/types.ts

Types

This package is fully typed with TypeScript.

Enums

Interfaces

Type Definitions

Contribute

See CONTRIBUTING.md.