Skip to content

Commit 6dbb98a

Browse files
authored
add troubleshoot on documentation and some lint minor refactors (#3934)
* docs: add troubleshooting * refactor(lint): use RuleConfigSeverity in errors and warnings filter * refactor(lint): rewrite missing rule error message
1 parent dd7a6f7 commit 6dbb98a

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

@commitlint/lint/src/lint.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ test('throws for invalid rule names', async () => {
9393
bar: [RuleConfigSeverity.Warning, 'never'],
9494
});
9595

96-
await expect(error).rejects.toThrow(/^Found invalid rule names: foo, bar/);
96+
await expect(error).rejects.toThrow(
97+
/^Found rules without implementation: foo, bar/
98+
);
9799
});
98100

99101
test('throws for invalid rule config', async () => {

@commitlint/lint/src/lint.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ export default async function lint(
7979
if (missing.length > 0) {
8080
const names = [...allRules.keys()];
8181
throw new RangeError(
82-
`Found invalid rule names: ${missing.join(
83-
', '
84-
)}. Supported rule names are: ${names.join(', ')}`
82+
[
83+
`Found rules without implementation: ${missing.join(', ')}.`,
84+
`Supported rules are: ${names.join(', ')}.`,
85+
].join('\n')
8586
);
8687
}
8788

@@ -181,10 +182,10 @@ export default async function lint(
181182
);
182183

183184
const errors = results.filter(
184-
(result) => result.level === 2 && !result.valid
185+
(result) => result.level === RuleConfigSeverity.Error && !result.valid
185186
);
186187
const warnings = results.filter(
187-
(result) => result.level === 1 && !result.valid
188+
(result) => result.level === RuleConfigSeverity.Warning && !result.valid
188189
);
189190

190191
const valid = errors.length === 0;

docs/.vitepress/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default defineConfig({
6868
base: '/support',
6969
collapsed: true,
7070
items: [
71+
{text: 'Troubleshooting', link: '/troubleshooting'},
7172
{text: 'Releases', link: '/releases'},
7273
{text: 'Upgrade commitlint', link: '/upgrade'},
7374
],

docs/support/troubleshooting.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Troubleshooting
2+
3+
## Getting `Range error: Found invalid rule names: [...]` after update {#range-error-invalid-rule}
4+
5+
After updating one or more `@commitlint` packages you might encounter an error like:
6+
7+
```text
8+
Found invalid rule names: header-trim.
9+
Supported rule names are: body-case, body-empty, ...
10+
```
11+
12+
The source of this error is likely a mismatch of version between `@commitlint` packages in `node_modules`.
13+
14+
E.g.: you might have a config requesting a rule that is not included in `@commitlint/rules`.
15+
16+
> [!TIP]
17+
> If you are relying on a config which depends on an earlier version of `@commitlint/config-conventional` be sure to update them:
18+
>
19+
> ```sh
20+
> npm update @commitlint/config-conventional
21+
> ```
22+
23+
---
24+
25+
> [!NOTE]
26+
> Detailed explanation about the error can be found in this [comment](https://github.com/conventional-changelog/commitlint/pull/3871#issuecomment-1911455325).

0 commit comments

Comments
 (0)