question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
samsonmaconicommented, Mar 27, 2021

@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']
    }
  }
};
1reaction
lewisdalycommented, Feb 11, 2021

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - Exclamation Mark in type definition - Stack Overflow
My question is now whether the exclamation mark before a type definition has exactly the same meaning like in a normal context.
Read more >
@commitlint/config-angular - npm
subject-exclamation-mark​​ The angular commit convention does not use a ! to define a breaking change in the commit subject. If you want to...
Read more >
Understanding the exclamation mark in TypeScript
The exclamation mark ! is known as the non-null assertion operator in TypeScript. We will be using these terms interchangeably in this ...
Read more >
@commitlint/config-conventional | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
How are you writing a commit message?
git commit -m "feat: allow the provided config object to extend other ... An exclamation mark ! can be added before the type/scope...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found