blob: 53e3a635a1cce0fcebcb690a7a69bd4606663d98 [file] [log] [blame]
Chris Kayfa3a1382021-11-12 15:48:44 +00001/*
Yann Gautier6c6e9862024-11-21 10:58:11 +01002 * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
Chris Kayfa3a1382021-11-12 15:48:44 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/* eslint-env es6 */
8
9"use strict";
10
Yann Gautier6c6e9862024-11-21 10:58:11 +010011import fs from "fs";
12import rules from "@commitlint/rules";
13import yaml from "js-yaml";
Chris Kayfa3a1382021-11-12 15:48:44 +000014
Chris Kayc4e8eda2021-11-09 20:05:38 +000015/*
Chris Kayf64c5582021-12-01 16:34:55 +000016 * The types and scopes accepted by both Commitlint and Commitizen are defined by the changelog
17 * configuration file - `changelog.yaml` - as they decide which section of the changelog commits
18 * with a given type and scope are placed in.
Chris Kayc4e8eda2021-11-09 20:05:38 +000019 */
Chris Kayc4e8eda2021-11-09 20:05:38 +000020
Chris Kayf64c5582021-12-01 16:34:55 +000021let changelog;
22
23try {
24 const contents = fs.readFileSync("changelog.yaml", "utf8");
25
26 changelog = yaml.load(contents);
27} catch (err) {
28 console.log(err);
29
30 throw err;
31}
32
33function getTypes(sections) {
34 return sections.map(section => section.type)
35}
36
37function getScopes(subsections) {
38 return subsections.flatMap(subsection => {
Yann Gautier6c6e9862024-11-21 10:58:11 +010039 const scope = subsection.scope ? [subsection.scope] : [];
Chris Kayf64c5582021-12-01 16:34:55 +000040 const subscopes = getScopes(subsection.subsections || []);
Chris Kayc4e8eda2021-11-09 20:05:38 +000041
42 return scope.concat(subscopes);
43 })
44};
45
Chris Kayf64c5582021-12-01 16:34:55 +000046const types = getTypes(changelog.sections).sort(); /* Sort alphabetically */
47const scopes = getScopes(changelog.subsections).sort(); /* Sort alphabetically */
Chris Kayc4e8eda2021-11-09 20:05:38 +000048
Yann Gautier6c6e9862024-11-21 10:58:11 +010049export default {
Chris Kayfa3a1382021-11-12 15:48:44 +000050 extends: ["@commitlint/config-conventional"],
51 plugins: [
52 {
53 rules: {
Yann Gautier6c6e9862024-11-21 10:58:11 +010054 "signed-off-by-exists": rules["trailer-exists"],
55 "change-id-exists": rules["trailer-exists"],
Chris Kayfa3a1382021-11-12 15:48:44 +000056 },
57 },
58 ],
59 rules: {
Chris Kayf64c5582021-12-01 16:34:55 +000060 "header-max-length": [1, "always", 50], /* Warning */
61 "body-max-line-length": [1, "always", 72], /* Warning */
Chris Kayfa3a1382021-11-12 15:48:44 +000062
63 "change-id-exists": [1, "always", "Change-Id:"], /* Warning */
64 "signed-off-by-exists": [1, "always", "Signed-off-by:"], /* Warning */
Chris Kayc4e8eda2021-11-09 20:05:38 +000065
Yann Gautier6c6e9862024-11-21 10:58:11 +010066 "type-case": [2, "always", "lower-case"], /* Error */
Chris Kayf64c5582021-12-01 16:34:55 +000067 "type-enum": [2, "always", types], /* Error */
68
Yann Gautier804e52e2021-11-19 17:57:50 +010069 "scope-case": [2, "always", "lower-case"], /* Error */
Chris Kayc4e8eda2021-11-09 20:05:38 +000070 "scope-enum": [1, "always", scopes] /* Warning */
Chris Kayfa3a1382021-11-12 15:48:44 +000071 },
72};