Skip to content

Commit 1ca167c

Browse files
kyliaualan-agius4
authored andcommitted
build: update validate-commits script to list valid types and scopes
The commit linter expects a certain type and/or scope in the commit message, but if the right type/scope is not provided it doesn't tell us what to do. Instead of this: ``` The following commit has an unknown type. You can use wip: to avoid this. ``` It now outputs this: ``` The following commit has an unknown type. It must be one of [docs, refactor, style, test, feat, fix, build, revert, ci, release]. You can use wip: to avoid this. ```
1 parent 2388806 commit 1ca167c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/validate-commits.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,25 +154,27 @@ export default function (argv: ValidateCommitsOptions, logger: logging.Logger) {
154154
}
155155

156156
const [type, scope] = subject.slice(1);
157+
const validTypes = Object.keys(types).join(', ');
158+
const validScopes = Object.keys(packages).join(', ');
157159
if (!(type in types)) {
158-
_invalid(sha, message, 'has an unknown type. You can use wip: to avoid this.');
160+
_invalid(sha, message, `has an unknown type. Valid types are [${validTypes}]. You can use wip: to avoid this.`);
159161
continue;
160162
}
161163
switch (types[type].scope) {
162164
case Scope.Either:
163165
if (scope && !packages[scope]) {
164-
_invalid(sha, message, 'has a scope that does not exist');
166+
_invalid(sha, message, `has a scope that does not exist. Valid scopes are [${validScopes}].`);
165167
continue;
166168
}
167169
break;
168170

169171
case Scope.MustHave:
170172
if (!scope) {
171-
_invalid(sha, message, 'should always have a scope');
173+
_invalid(sha, message, `should always have a scope. Valid scopes are [${validScopes}].`);
172174
continue;
173175
}
174176
if (!packages[scope]) {
175-
_invalid(sha, message, 'has a scope that does not exist');
177+
_invalid(sha, message, `has a scope that does not exist. Valid scopes are [${validScopes}].`);
176178
continue;
177179
}
178180
break;

0 commit comments

Comments
 (0)