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.

Can't use async rule configuration

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alebiancocommented, Nov 15, 2021

All existing tests should still pass.

yes all existing tests are fine with the change

I assume here a new test with the async config should de added

agree, that looks like the right place, thanks

I’ll open the PR once I have the time to add a couple tests

0reactions
escapedcatcommented, Nov 15, 2021

I’ll open the PR once I have the time to add a couple tests

No rush, thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Async/Await - Best Practices in Asynchronous Programming
Async all the way, Don't mix blocking and async code, Console main method. Configure context, Use ConfigureAwait(false) when you can, Methods that require ......
Read more >
Is it possible to use async await in rules? - Auth0 Community
Yes, you can use async/await in a rule. You can use it in a function that you define, or you can use it...
Read more >
How do I get a warning in Visual Studio when async methods ...
From Options,. Go to Text Editor → Basic → Code Style → Naming; Select Manage Specifications and Add New Specification; Select Method, ...
Read more >
Can't use async functions and generators · Issue #17 - GitHub
I've found that regeneratorRuntime is disabled. I'm trying to run react-coroutine in the setup of preact and preact-cli but I'm not able to...
Read more >
How we can assure Async Business rule run and how
Hi. I have created a REST outbound service API and while testing i successfully called the 3rd party API. Using the preview script...
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