1/* 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 14/* 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 32module.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 */ 48 49 "scope-case": [2, "always", "kebab-case"], /* Error */ 50 "scope-enum": [1, "always", scopes] /* Warning */ 51 }, 52}; 53