Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 55 additions & 12 deletions commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
const PUBLIC_PACKAGES = [
"builder",
"cli",
"documentation",
"fs",
"logger",
"project",
"server",
];

const INTERNAL_PACKAGES = [
"documentation",
"shrinkwrap-extractor"
];

const ALLOWED_TYPE_SCOPE_COMBINATIONS = {
"build": ["deps-dev"],
"ci": ["github-actions", "release-please"],
"deps": [...PUBLIC_PACKAGES, ...INTERNAL_PACKAGES],
"feat": PUBLIC_PACKAGES,
"fix": PUBLIC_PACKAGES,
};

const ALL_SCOPES = Object.values(ALLOWED_TYPE_SCOPE_COMBINATIONS).flat();

export default {
extends: [
"@commitlint/config-conventional",
Expand Down Expand Up @@ -31,23 +56,41 @@ export default {
"scope-enum": [
2,
"always",
[
// Package names
"builder",
"cli",
"documentation",
"fs",
"logger",
"project",
"server",
// Special scope for dev dependencies
"deps-dev"
]
ALL_SCOPES,
],
"scope-case": [2, "always", "lowercase"],

// Enable custom rule for type-scope combinations (see code below)
"custom/type-scope-combination": [
2,
"always",
],
},
ignores: [
// Ignore release commits, as their subject doesn't start with an uppercase letter
(message) => message.startsWith("release: v"),
],
plugins: [
{
rules: {
"custom/type-scope-combination": ({type, scope}) => {
// If no scope, it's valid
if (!scope) {
return [true];
}
// If type not in restrictions, allow any scope
if (!ALLOWED_TYPE_SCOPE_COMBINATIONS[type]) {
return [true];
}
// Check if the combination is allowed
const isAllowed = ALLOWED_TYPE_SCOPE_COMBINATIONS[type].includes(scope);
return [
isAllowed,
`Scope "${scope}" is not allowed with type "${type}". ` +
`Allowed scopes: ${ALLOWED_TYPE_SCOPE_COMBINATIONS[type].join(", ")}`
];
}
}
}
]
};