blob: f97048188a1a23ae521e3e8a40040a2a2926c587 [file] [log] [blame]
Chris Kay285c1302021-11-12 15:48:44 +00001/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/* eslint-env es6 */
8
9"use strict";
10
11const cz = require("./.cz.json");
12const { "trailer-exists": trailerExists } = require("@commitlint/rules").default;
13
Chris Kay025c87f2021-11-09 20:05:38 +000014/*
15 * Recursively fetch the project's supported scopes from the Commitizen configuration file. We use
16 * permit only the blessed scope for each section to encourage developers to use a consistent scope
17 * scheme.
18 */
19function getScopes(sections) {
20 return sections.flatMap(section => {
21 const scopes = section.scopes;
22 const subscopes = getScopes(section.sections || []);
23
24 const scope = scopes ? [ scopes[0] ] : []; /* Only use the blessed scope */
25
26 return scope.concat(subscopes);
27 })
28};
29
30const scopes = getScopes(cz.sections); /* Contains every blessed scope */
31
Chris Kay285c1302021-11-12 15:48:44 +000032module.exports = {
33 extends: ["@commitlint/config-conventional"],
34 plugins: [
35 {
36 rules: {
37 "signed-off-by-exists": trailerExists,
38 "change-id-exists": trailerExists,
39 },
40 },
41 ],
42 rules: {
43 "body-max-line-length": [1, "always", cz.maxLineWidth], /* Warning */
44 "header-max-length": [1, "always", cz.maxHeaderWidth], /* Warning */
45
46 "change-id-exists": [1, "always", "Change-Id:"], /* Warning */
47 "signed-off-by-exists": [1, "always", "Signed-off-by:"], /* Warning */
Chris Kay025c87f2021-11-09 20:05:38 +000048
Yann Gautier54b08f92021-11-19 17:57:50 +010049 "scope-case": [2, "always", "lower-case"], /* Error */
Chris Kay025c87f2021-11-09 20:05:38 +000050 "scope-enum": [1, "always", scopes] /* Warning */
Chris Kay285c1302021-11-12 15:48:44 +000051 },
52};