conventional-changelog / conventional-changelog/commitlint

[Help/Question] How to add scope dynamically?

Open
#1,996 3 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
TypeScript
Stars
18.7k
Forks
970
Avg merge
7h 33m
Merged PRs (30d)
49

Description

## Expected Behavior

When creating a commit be able to identify from where (packages) the files are coming from:

```bash
$ git commit -m "feat: adding a new DB adapter for X" # (on packages A)
$ git commit -m "fix: this will solve a problem on the Service Z" # (on packages B)
$ git commit -m "chore: update eslint-config-custom to version 0.4.2" # (on packages A, B, C)
```

And we format the message given the package/scope they changes are coming from:
```bash
ccc64c55 "feat(A): adding a new database adapter for X"
42bc938a "fix(B): this will solve a problem on the Service Z"
9f4fe8d3 "chore: update eslint-config-custom to version 0.4.2"
```

## Current Behavior

When writing a commit we're obligated to define the `scope` of the package, and to avoid forgetting it we add the rule `'scope-empty': [2, 'never']` to enforce this definition when generating our CHANGELOG file.

The only way now is by always adding the `(scope)` manually as we couldn't find an easy way to adding it dynamically by detecting from which package the affected files are coming from.

**There's an approach we can follow by reading the commit message/title and the staged files?**

## Current config

commitlint.config.js

```js
const { getPackages } = require('@commitlint/config-lerna-scopes').utils;

module.exports = {
extends: [
'@commitlint/config-conventional',
'@commitlint/config-lerna-scopes',
],
rules: {
'scope-case': [2, 'always', ['lower-case', 'pascal-case', 'camel-case']],
'scope-enum': async (ctx) => {
const pkgs = await getPackages(ctx);
return [2, 'always', [...pkgs, 'deps', 'release']]
},
'scope-empty': [2, 'never'],
'header-max-length': [2, 'always', 100],
},
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.