.commitlintrc.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2021, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /* eslint-env es6 */
  7. "use strict";
  8. const fs = require("fs");
  9. const yaml = require("js-yaml");
  10. const { "trailer-exists": trailerExists } = require("@commitlint/rules").default;
  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. module.exports = {
  37. extends: ["@commitlint/config-conventional"],
  38. plugins: [
  39. {
  40. rules: {
  41. "signed-off-by-exists": trailerExists,
  42. "change-id-exists": trailerExists,
  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. };