From 3c603c7c79ef9633cc9fe07f97e300dd41ff2c42 Mon Sep 17 00:00:00 2001 From: Nico Ismaili Date: Mon, 5 Feb 2024 00:40:22 +0100 Subject: [PATCH] feat(deps): migrates to commitlint-plugin-spend /spend 5m --- commitlint.config.ts | 47 ++------------------------------------------ package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/commitlint.config.ts b/commitlint.config.ts index d16e2b6..fe85d73 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -1,50 +1,7 @@ module.exports = { extends: [`@commitlint/config-conventional`], rules: { - "require-spent": [2, `always`], + spend: [2, `always`], }, - plugins: [ - { - rules: { - "require-spent": ({ raw }: { raw: string }) => { - const commitMessage = raw.trim(); - - const msgSplit = commitMessage.split(`\n`); - if (msgSplit.length < 3) - return [ - false, - `'/spent' directive must be in new line separated by another new line`, - ]; // ensure that commit message has more than 1 line - - if (msgSplit[1] !== ``) - return [ - false, - `'/spent' directive must be separated by another new line`, - ]; // ensure that commit message has more than 1 line - - const spentSplit = msgSplit[msgSplit.length - 1].split(` `); - const isCorrectCommand = - spentSplit[0] === `/spent` || spentSplit[0] === `/spend`; - if (spentSplit.length < 2 || !isCorrectCommand) - return [ - false, - `the last line of a commit must be a '/spent' directive`, - ]; // ensure that commit message ends with '/spent' - - const spentTimeValue = spentSplit[spentSplit.length - 1].trim(); - const regex = /^(\d|[1-5]\d)m|(([1-9]|[1-4]\d)h(\d|[1-5]\d)?m?)$/; // 1h30, 30m, 1h, 1h30m, 1h30, 1h30m - const matches = regex.exec(spentTimeValue); - - if (!matches || matches[0].length !== spentTimeValue.length) { - // ensure that spent time value is valid - return [ - false, - `Commit message must end with a valid spent time with the format '/spent 1h30' or '/spent 30m' or '/spent 1h'`, - ]; - } - return [true]; - }, - }, - }, - ], + plugins: [`commitlint-plugin-spend`], }; diff --git a/package.json b/package.json index 9da3d3b..41bdb4f 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@typescript-eslint/parser": "^6.20.0", "@vitest/coverage-v8": "^1.2.2", "c8": "^9.1.0", + "commitlint-plugin-spend": "^1.0.1", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-config-standard": "^17.1.0", diff --git a/yarn.lock b/yarn.lock index f432e4b..ecada70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5226,6 +5226,11 @@ commander@^7.2.0: resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7" integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw== +commitlint-plugin-spend@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/commitlint-plugin-spend/-/commitlint-plugin-spend-1.0.1.tgz#8dc8a0cfb48a923a584cc64d86e03d651e544417" + integrity sha512-YIz6WSQQVqyGWPLSB3m5LuVlNuEDYkK50bafAufCYw7UmONDN1T4z8oqGLMIpKbCMyBf3NORjLI3HD1tJunqAw== + common-path-prefix@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/common-path-prefix/-/common-path-prefix-3.0.0.tgz#7d007a7e07c58c4b4d5f433131a19141b29f11e0"