Chris Kay | 285c130 | 2021-11-12 15:48:44 +0000 | [diff] [blame] | 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 | |
| 11 | const cz = require("./.cz.json"); |
| 12 | const { "trailer-exists": trailerExists } = require("@commitlint/rules").default; |
| 13 | |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 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 | */ |
| 19 | function 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 | |
| 30 | const scopes = getScopes(cz.sections); /* Contains every blessed scope */ |
| 31 | |
Chris Kay | 285c130 | 2021-11-12 15:48:44 +0000 | [diff] [blame] | 32 | module.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 Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 48 | |
Yann Gautier | 54b08f9 | 2021-11-19 17:57:50 +0100 | [diff] [blame] | 49 | "scope-case": [2, "always", "lower-case"], /* Error */ |
Chris Kay | 025c87f | 2021-11-09 20:05:38 +0000 | [diff] [blame] | 50 | "scope-enum": [1, "always", scopes] /* Warning */ |
Chris Kay | 285c130 | 2021-11-12 15:48:44 +0000 | [diff] [blame] | 51 | }, |
| 52 | }; |