Skip to content

feat: how to mitigate errors when adding a new rule and not updating all relevant packages #3894

Closed
@marcalexiei

Description

@marcalexiei

Expected Behavior

See context

Current Behavior

See context

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

  1. Adding a "troubleshooting" section in the docs explaining the reason of the issue and how to resolve it.
  2. Integrate RangeError: Found invalid rule names with an additional description providing the user a clue that some @commitlint/packages should be updated (a link to the new documentation section could do the trick).

What do you think? If you agree I can work on a PR.

Context

After adding header-trim rule (#3871),
a certain amount of user has reported issues when updating commitlint:

  1. feat(rules): add header-trim rule #3871 (comment)
  2. feat(rules): add header-trim rule #3871 (comment)
  3. feat(rules): add header-trim rule #3871 (comment)

For reference:

Explanation of the cause of the error

The error is thrown here:

if (missing.length > 0) {
const names = [...allRules.keys()];
throw new RangeError(
`Found invalid rule names: ${missing.join(
', '
)}. Supported rule names are: ${names.join(', ')}`
);
}

all rules is declared reading the content of baseRules:

const allRules: Map<string, BaseRule<never, RuleType>> = new Map(
Object.entries(defaultRules)
);

baseRules are imported from @commitlint-rules:

import defaultRules from '@commitlint/rules';

in version 14.6.0 header-trim definition has been added

'header-trim': headerTrim,


Running command line from CLI doesn't throw any error.
If I have to make a guess not all required packages have updated to version 18.6.0.

Originally posted by @marcalexiei in #3871 (comment)

Solution

[!WARNING]
The source of this error is likely a mismatch of version between @commitlint packages in node_modules

Detailed explanation can be found in a comment above.

If someone is relying on a config which depends on an earlier version of @commitlint/config-conventional be sure to update it:

npm update @commitlint/config-conventional

Originally posted by @marcalexiei in #3871 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions