.commitlintrc.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /* eslint-env es6 */
  7. "use strict";
  8. import fs from "fs";
  9. import rules from "@commitlint/rules";
  10. import yaml from "js-yaml";
  11. /*
  12. * The types and scopes accepted by both Commitlint and Commitizen are defined by the changelog
  13. * configuration file - `changelog.yaml` - as they decide which section of the changelog commits
  14. * with a given type and scope are placed in.
  15. */
  16. let changelog;
  17. try {
  18. const contents = fs.readFileSync("changelog.yaml", "utf8");
  19. changelog = yaml.load(contents);
  20. } catch (err) {
  21. console.log(err);
  22. throw err;
  23. }
  24. function getTypes(sections) {
  25. return sections.map(section => section.type)
  26. }
  27. function getScopes(subsections) {
  28. return subsections.flatMap(subsection => {
  29. const scope = subsection.scope ? [subsection.scope] : [];
  30. const subscopes = getScopes(subsection.subsections || []);
  31. return scope.concat(subscopes);
  32. })
  33. };
  34. const types = getTypes(changelog.sections).sort(); /* Sort alphabetically */
  35. const scopes = getScopes(changelog.subsections).sort(); /* Sort alphabetically */
  36. export default {
  37. extends: ["@commitlint/config-conventional"],
  38. plugins: [
  39. {
  40. rules: {
  41. "signed-off-by-exists": rules["trailer-exists"],
  42. "change-id-exists": rules["trailer-exists"],
  43. },
  44. },
  45. ],
  46. rules: {
  47. "header-max-length": [1, "always", 50], /* Warning */
  48. "body-max-line-length": [1, "always", 72], /* Warning */
  49. "change-id-exists": [1, "always", "Change-Id:"], /* Warning */
  50. "signed-off-by-exists": [1, "always", "Signed-off-by:"], /* Warning */
  51. "type-case": [2, "always", "lower-case"], /* Error */
  52. "type-enum": [2, "always", types], /* Error */
  53. "scope-case": [2, "always", "lower-case"], /* Error */
  54. "scope-enum": [1, "always", scopes] /* Warning */
  55. },
  56. };