Skip to content

Can't use async rule configuration #2868

Closed
@alebianco

Description

@alebianco

Expected Behavior

In a typescript project, provide an asynchronous list for the scope-enum rule, as described in the doc https://github.com/conventional-changelog/commitlint/blob/master/docs/reference-rules.md

Current Behavior

Typescript complains of a type mismatch and the code is not compiled

Affected packages

  • types

Possible Solution

I don't think the QualifiedConfig type is correct for the async option. It should probably be (() => Promise<RuleConfigTuple<T>>) instead.

Steps to Reproduce (for bugs)

  1. Try to compile the typescript configuration provided to javascript with tsc
commitlint.config.ts
import type { RulesConfig } from '@commitlint/types';
import { RuleConfigSeverity } from '@commitlint/types';

const { Error } = RuleConfigSeverity;

export const rules: Partial<RulesConfig> = {
  'scope-enum': () => Promise.resolve([Error, 'always', ['one', 'two', 'three']]),
};

export default {
  rules,
};

Context

I want to restrict commit scopes to a predefined list that cannot be defined synchronously. I have to define a custom rule/plugin to work around this issue.

Your Environment

Executable Version
commitlint --version 14.1.0
git --version V2.33.1
node --version v16.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions