From 434b512d17af2da3992ffe81bfe4401d369f4913 Mon Sep 17 00:00:00 2001 From: Luis Saavedra Date: Wed, 1 Dec 2021 10:16:58 -0500 Subject: [PATCH] feat(build): #769.1 add commit lint config - Add commit lint config files --- makes.nix | 2 + .../lint-git-commit-msg-config.js | 60 +++++++++++++++++++ .../lint-git-commit-msg-parser.js | 6 ++ 3 files changed, 68 insertions(+) create mode 100644 test/lint-commit-msg/lint-git-commit-msg-config.js create mode 100644 test/lint-commit-msg/lint-git-commit-msg-parser.js diff --git a/makes.nix b/makes.nix index fab13c9b..ad580ade 100644 --- a/makes.nix +++ b/makes.nix @@ -95,6 +95,8 @@ lintGitCommitMsg = { enable = true; branch = "main"; + parser = "/test/lint-commit-msg/lint-git-commit-msg-parser.js"; + config = "/test/lint-commit-msg/lint-git-commit-msg-config.js"; }; lintGitMailMap = { enable = true; diff --git a/test/lint-commit-msg/lint-git-commit-msg-config.js b/test/lint-commit-msg/lint-git-commit-msg-config.js new file mode 100644 index 00000000..269b2f41 --- /dev/null +++ b/test/lint-commit-msg/lint-git-commit-msg-config.js @@ -0,0 +1,60 @@ +const HEADERLENGTHMAX = 60; +const LINELENGTHMAX = 72; +const BODYLENGTHMIN = 15; + +module.exports = { + parserPreset: './.commitlint-parser-preset', + rules: { + + // Body + 'body-leading-blank': [2, 'always'], // blank line between header and body + 'body-empty': [2, 'never'], // body cannot be empty + 'body-max-line-length': [2, 'always', LINELENGTHMAX], // body lines max chars LINELENGTHMAX + 'body-min-length' : [2, 'always', BODYLENGTHMIN], // body more than BODYLENGTHMIN chars + + // Footer + 'footer-leading-blank': [2, 'always'], // blank line between body and footer + 'footer-max-line-length': [2, 'always', LINELENGTHMAX], // footer lines max chars LINELENGTHMAX + + // Header + 'header-case': [2, 'always', 'lower-case'], // header lower case + 'header-max-length': [2, 'always', HEADERLENGTHMAX], // header max chars HEADERLENGTHMAX + + // Scope + 'scope-empty': [2, 'never'], // scope always + 'scope-enum': [ + 2, + 'always', + [ + 'front', // Front-End change + 'back', // Back-End change + 'infra', // Infrastructure change + 'conf', // Configuration files change + 'build', // System component change (ci, scons, webpack...) + 'job', // asynchronous or schedule tasks (backups, maintainance...) + 'cross', // Mix of two or more scopes + 'doc', // Documentation only changes + ], + ], + + // Subject (commit title without type and scope) + 'subject-case': [2, 'always', 'lower-case'], // subject lower-case + 'subject-empty': [2, 'never'], // subject always + + // Type + 'type-empty': [2, 'never'], //type always + 'type-enum': [ + 2, + 'always', + [ + 'feat', // New feature + 'perf', // Improves performance + 'fix', // Bug fix + 'rever', // Revert to a previous commit in history + 'style', // Do not affect the meaning of the code (formatting, etc) + 'refac', // Neither fixes a bug or adds a feature + 'test', // Adding missing tests or correcting existing tests + ], + ], + }, +}; diff --git a/test/lint-commit-msg/lint-git-commit-msg-parser.js b/test/lint-commit-msg/lint-git-commit-msg-parser.js new file mode 100644 index 00000000..aef759b2 --- /dev/null +++ b/test/lint-commit-msg/lint-git-commit-msg-parser.js @@ -0,0 +1,6 @@ +module.exports = { + parserOpts: { + headerPattern: /^(\w*)\((\w*)\):\s(#[0-9]\d*)(.\d+)?\s(.*)$/, + headerCorrespondence: [ 'type', 'scope', 'ticket', 'part', 'subject' ], + }, +};