Skip to content

Print commit message after error message if it is invalid #222

Closed
@dnamorim

Description

@dnamorim

Currently, when using the CLI, if the message is invalid we lose all its content (using a custom message in VIM mode), which might be a little frustrating when we a have a long commit body, so it would be nice if we show the previous message after the linting errors.

Expected Behavior

If the message fails it could be printed to after the error message like:

⧗   input:
foo

Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum iure distinctio atque dolorum 
ratione? Ullam, impedit nemo. Porro, quasi. Tempore rem facere ut enim dolores consequuntur illo 
maiores consequatur provident.

✖   type may not be empty [type-empty]
✖   found 1 problems, 0 warnings

Current Behavior

Currently, it only shows the following output:

⧗   input: foo
✖   type may not be empty [type-empty]
✖   found 1 problems, 0 warnings

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

This can be done in the @commitlint/cli/src/cli.js module by not splitting the message by \n in case of error so we have access to the whole message to further edit.

Steps to Reproduce (for bugs)

  1. Create a config file as described below.
  2. Create a commit message with a body like:
 foo

 Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum iure distinctio atque dolorum 
 ratione? Ullam, impedit nemo. Porro, quasi. Tempore rem facere ut enim dolores consequuntur illo 
 maiores consequatur provident.
  1. The message will be invalid and the input only refers to the commit title.
commitlint.config.js
module.exports = {
  rules: {
    'type-empty': [2, 'never']
  }
};

Context

In our workflow, the commit messages are as much detailed as possible since their contents are used to create the PR description. If the message is very long it is quite frustrating if something is invalid and we lose all the previous work.

Your Environment

Executable Version
commitlint --version 5.2.8
git --version 2.14.3
node --version 8.9.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions