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