Skip to content

Messages with an exclamation mark after type ("feat!") fail with Angular config #2226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 4 tasks
aleksator opened this issue Oct 21, 2020 · 11 comments
Closed
1 of 4 tasks
Labels

Comments

@aleksator
Copy link

Indicating breaking changes with ! after type does not work when extending Angular config, but should be possible according to Conventional Commits 1.0.0.

I'm using this project through the Github Action, which currently uses commitlint 9.0.1 under the hood.

Expected Behavior

Commit message like feat!: the message has an exclamation mark should pass the lint.

Current Behavior

Lint does not pass with the following error message:

⧗ input: feat!: the message has an exclamation mark
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

A workaround is to extend config-conventional instead.
.commitlintrc.yml:

extends:
  - '@commitlint/config-conventional'

Since they are different, desired rules from config-angular have to also be defined below, but they are not relevant to this bug so they have been omitted.

A proper solution would be to fix this in commitlint.

Steps to Reproduce (for bugs)

  1. In the repository root create file:
    .commitlintrc.yml:
extends:
  - '@commitlint/config-angular'
  1. Enable Github Actions with the following configuration:
    .github/workflows/ci.yml:
name: CI
on:
  pull_request:
  push:

jobs:
  check_commit_conventions:
    name: Check commit conventions
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Check commit conventions
        uses: wagoid/commitlint-github-action@v2
        with:
          configFile: .commitlintrc.yml
          failOnWarnings: true
  1. Push a commit with an exclamation mark and check CI pipeline.

A commenter from another issue faced problems with the version 9.0.1 as well, although he had them with config-conventional, so it might be a separate problem.

@evanstoddard23
Copy link

I am getting the same error even when extending @commitlint/config-conventional

aleksator added a commit to pubgrub-rs/pubgrub that referenced this issue Oct 24, 2020
@aleksator
Copy link
Author

I am getting the same error even when extending @commitlint/config-conventional

@evanstoddard23 You can see the exact workaround that worked for us here: pubgrub-rs/pubgrub#51.
Maybe it will help you troubleshoot the differences.

@KarthikNedunchezhiyan
Copy link

@aleksator how this workaround (pubgrub-rs/pubgrub#51) allows "!" along with type like "refractor!: drop some support" ? can you please explain operation performed?

@KarthikNedunchezhiyan
Copy link

I am getting the same error even when extending @commitlint/config-conventional

@evanstoddard23 found any fix/workaround for this issue?

@bytestream
Copy link

I came across this issue using @commitlint/config-conventional in a NodeJS app. It turned out I was incorrectly using:

import configConventional from '@commitlint/config-conventional';
import lint from '@commitlint/lint';

lint('refactor!: drop node 6 support', configConventional.rules);

I switched to using @commitlint/load as documented on the website and the issue was resolved 🎉

@aleksator
Copy link
Author

@aleksator how this workaround (pubgrub-rs/pubgrub#51) allows "!" along with type like "refractor!: drop some support" ? can you please explain operation performed?

I'm not a developer of commitlint so I can't explain why it works. I haven't dug into the issue, otherwise this would be a PR.
That's just a workaround I found that makes Github Action pass.

@escapedcat escapedcat added the bug label Dec 31, 2020
@lewisdaly
Copy link

I switched to using @commitlint/load as documented on the website and the issue was resolved

Thanks for the tip! I was surprised how long it took me to figure this out, but in the end, the cli.ts has a clue:

https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/cli/src/cli.ts#L199

I found this worked for me in the end:

const loadedRules = await load({
    extends: [ '@commitlint/config-conventional' ],
  })
  const opts = {
    parserOpts: loadedRules.parserPreset.parserOpts
  }
  const lintResult = await lint(title, loadedRules.rules, opts)

@zavoloklom
Copy link

zavoloklom commented Feb 25, 2021

I have this error on "commit-msg" git hook with command npx commitlint < "$1"

My test config:

module.exports = {
	rules: {
		'type-empty': [2, 'never'],
		'subject-empty': [2, 'never'],
	},
};

Console output:

⧗   input: feat!: test site config
✖   type may not be empty [type-empty]
✖   subject may not be empty [subject-empty]

✖   found 2 problems, 0 warnings

Versions: 11.0.0 and 12.0.1


Seems like exclamation mark prevent correct dividing this line to type and subject.

@samsonmaconi
Copy link

@aleksator how this workaround (pubgrub-rs/pubgrub#51) allows "!" along with type like "refractor!: drop some support" ? can you please explain operation performed?

I came across the issue as well using config-angular and also config-conventional
Did a lil digging, and found it's just a regex pattern mismatch. Not a bug.

config-angular has headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/ and
config-conventional has headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/

If there's no match due to the introduction of a ! the commit type and scope will not be found

I needed to match fix!(170793): whats poppin son and neither would work for me.
Although config-conventional allows fix(170793)!: whats poppin son or fix!: whats poppin son, it isn't what I wanted.

This is what I used:

// commitlint.config.js

module.exports = {
  extends: [
    "@commitlint/config-angular",
    "@commitlint/parse"
  ],
  rules: {...},
  parserPreset: {
    parserOpts: {
      headerPattern: /^(\w*)!?(?:\((.*)\))?: (.*)$/,  // my custom header pattern
      headerCorrespondence: ['type', 'scope', 'subject'],
      revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i,
      revertCorrespondence: ['header', 'hash']
    }
  }
};

@AdeAttwood
Copy link
Member

This is a limitation to the @commitlint/config-angular if you want this feature, consider using @commitlint/config-conventional. I will close this for now, please reopen if there is anything else.

See @commitlint/config-angular/README.md

@beamery-tomht
Copy link

beamery-tomht commented Sep 2, 2021

Hello, was using this:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'body-leading-blank': [2, 'always'],
    'footer-leading-blank': [2, 'always'],
    'type-enum': [
      2,
      'always',
      ['feat', 'fix', 'docs', 'chore', 'refactor', 'test', 'revert'],
    ],
  },
  parserPreset: {
    parserOpts: {
      referenceActions: null,
      issuePrefixes: ['ISS-'],
    },
  },
};

Version 8, having the same issue.

Upgraded to latest version:

    "@commitlint/cli": "^13.1.0",
    "@commitlint/config-conventional": "^13.1.0",

The issue still persists...

edit: @samsonmaconi's suggestion for a custom parser has worked

module.exports = {
  extends: ['@commitlint/config-conventional', '@commitlint/parse'],
  rules: {
    'body-leading-blank': [2, 'always'],
    'footer-leading-blank': [2, 'always'],
    'type-enum': [
      2,
      'always',
      ['feat', 'fix', 'docs', 'chore', 'refactor', 'test', 'revert'],
    ],
  },
  parserPreset: {
    parserOpts: {
      headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/,
      referenceActions: null,
      issuePrefixes: ['ISS-'],
    },
  },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

10 participants