conventional-changelog/commitlint

The body is null when there is a reference like #XYZ in the commit message body

Fechada

#3.412 aberto em 25 de out. de 2022

 (0 comentário) (1 reação) (0 responsável)TypeScript (896 forks)batch import
help wantedparserplugin

Métricas do repositório

Stars
 (15.497 estrelas)
Métricas de merge de PR
 (Mesclagem média 12h 56m) (52 fundiu PRs em 30d)

Description

Steps to Reproduce (for bugs)

Develop a local plugin like documented here: https://github.com/conventional-changelog/commitlint/blob/master/docs/reference-plugins.md#local-plugins So the config file starts like this:

module.exports = {
    parserPreset: 'conventional-changelog-conventionalcommits',
    rules: {
        'body-leading-blank': [RuleStatus.Warning, 'always'],
        'body-soft-max-line-length': [RuleStatus.Error, 'always'],
        'footer-leading-blank': [RuleStatus.Warning, 'always'],
        'footer-max-line-length': [RuleStatus.Error, 'always', 150],
        'header-max-length': [RuleStatus.Error, 'always', 50],
        'subject-full-stop': [RuleStatus.Error, 'never', '.'],
        'type-empty': [RuleStatus.Warning, 'never'],
        'type-space-after-colon': [RuleStatus.Error, 'always'],
        'subject-lowercase': [RuleStatus.Error, 'always'],
        'body-prose': [RuleStatus.Error, 'always'],
        'type-space-after-comma': [RuleStatus.Error, 'always'],
        'trailing-whitespace': [RuleStatus.Error, 'always'],
        'prefer-slash-over-backslash': [RuleStatus.Error, 'always'],
        'type-space-before-paren': [RuleStatus.Error, 'always'],
        'proper-issue-refs': [RuleStatus.Error, 'always'],
    },
    plugins: [
        {
            rules: {
                'proper-issue-refs': ({body}: {body:any}) => {
                    let offence = false;   
                    if (body !== null) {
                        let bodyStr = convertAnyToString(body, "body");
                        console.log(bodyStr)
                        bodyStr = removeAllCodeBlocks(bodyStr);
                        offence = includeHashtagRef(bodyStr);
                    }

                    return [
                        !offence,
                        `Please use full URLs instead of #XYZ refs.`
                    ];
                },


...

  1. Run the plugin against a commit message like
"foo: this is only a title" + "\n\n" + "Bla blah bla #123.";

The body in the 'proper-issue-refs' rule becomes null. I found out commilint parser parses this commit in such a way that when there is a reference in the body it put the body information in a reference array like this:

    [
      {
        action: null,
        owner: null,
        repository: null,
        issue: '123',
        raw: 'Bla blah bla #123',
        prefix: '#'
      }
    ]

and the body argument becomes null. But I believe it shouldn't affect the body argument.

Current Behavior

The body argument is null when there is an issue reference like #XYZ in the commit message body.

Expected Behavior

The body argument shouldn't be null.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Your Environment

Executable Version
commitlint --version 17.1.2
git --version 2.38.0
node --version v16.17.1

Guia do colaborador