From 0a96ffefb4baf906cecda004c938f17ffdebf3ff Mon Sep 17 00:00:00 2001 From: Hangjit Rai Date: Sat, 12 Oct 2024 17:27:29 +1100 Subject: [PATCH 1/2] cleanup --- .husky/prepare-commit-msg | 39 ------------------------------------- package.json | 2 +- src/utils.js | 4 ++-- test/util.test.js | 5 +++++ yarn.lock | 41 ++++++++++++++++----------------------- 5 files changed, 25 insertions(+), 66 deletions(-) diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg index 8d5740d..ea53e71 100755 --- a/.husky/prepare-commit-msg +++ b/.husky/prepare-commit-msg @@ -5,42 +5,3 @@ # Bash sets the BASH environment variable, so if it is not set, then we # are running in a different shell, so manually run ourselves in BASH. -if [ -z "${BASH:-}" ]; then - exec bash "$0" "$@" -fi - -# Include any branches for which you wish to disable this script -if [ -z "$BRANCHES_TO_SKIP" ]; then - BRANCHES_TO_SKIP=(master develop staging test) -fi - -# Get the current branch name and check if it is excluded -BRANCH_NAME=$(git symbolic-ref --short HEAD) - -# Remove 'feature/' from the branch name for branch names like -# feature/PEN-23 so the BRANCH_NAME will be 'PEN-23' only -BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/feature\///gI') -BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$") - -# Remove 'bugfix/' from the branch name for branch names like -# bugfix/PEN-23 so the BRANCH_NAME will be 'PEN-23' only -BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/bugfix\///gI') -BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$") - -# Trim it down to get the parts we're interested in -TRIMMED=$(echo $BRANCH_NAME | sed -e 's:^\([^-]*-[^-]*\)-.*:\1:' -e \ - 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/') - -# Replace all the instances of the current branch name in the commit message - for amending commits -sed -i "s/$BRANCH_NAME\s/ /g" $1 - -# Delete BOTH leading and trailing whitespace from each line -sed -i 's/^[ \t]*//;s/[ \t]*$//' $1 - -# If it isn't excluded, prepend the trimmed branch identifier to the given message -if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]]; then - sed -i.bak -e "1s/^/$TRIMMED /" $1 -fi - -# Capitalise the first letter of each word -sed -i "s/\( \|^\|-\)\(.\)/\1\u\2/g" $1 diff --git a/package.json b/package.json index 63bbc52..ff77db4 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "nodemon": "^3.0.3", "prettier": "^3.2.5", "run-script-os": "^1.1.3", - "sinon": "^18.0.0", + "sinon": "^19.0.2", "web-ext": "^8.2.0", "web-ext-submit": "^7.8.0", "webextension-polyfill": "^0.12.0", diff --git a/src/utils.js b/src/utils.js index 1d7780d..6df4ec3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -164,7 +164,7 @@ export function setKeyValue(keyValueName, value) { } export function shouldCapitalise(text) { - const multilineRegex = /\s*\n+\s*\w$/; + const multilineRegex = /\s*\n+\s*[a-z]$/; let matches = multilineRegex.test(text); //console.log("matches:" + matches); @@ -173,7 +173,7 @@ export function shouldCapitalise(text) { return true; } - const sentenceRegex = /\w+\s*\W?([.?!])+\s+\w$/; + const sentenceRegex = /\w+\s*\W?([.?!])+\s+[a-z]$/; matches = sentenceRegex.test(text); if (!matches) { diff --git a/test/util.test.js b/test/util.test.js index ad32a6b..f5d6d6d 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -76,6 +76,8 @@ describe('util file tests', function () { expect(utils.shouldCapitalise(' k ')).toBe(false); expect(utils.shouldCapitalise(' k ')).toBe(false); expect(utils.shouldCapitalise(' ')).toBe(false); + expect(utils.shouldCapitalise(' 1')).toBe(false); + expect(utils.shouldCapitalise('this is ? 1')).toBe(false); expect(utils.shouldCapitalise('?')).toBe(true); expect(utils.shouldCapitalise('!')).toBe(true); @@ -97,6 +99,9 @@ describe('util file tests', function () { expect(utils.shouldCapitalise('war? lasting \n peace \n\n k')).toBe( true ); + + expect(utils.shouldCapitalise('war? \n\n 1')).toBe(false); + expect(utils.shouldCapitalise('war? \n\n 12')).toBe(false); }); test('shouldCapitalise_singleChar', () => { diff --git a/yarn.lock b/yarn.lock index cd8db74..b60f4d9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,13 +1463,6 @@ dependencies: type-detect "4.0.8" -"@sinonjs/fake-timers@11.2.2": - version "11.2.2" - resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz#50063cc3574f4a27bd8453180a04171c85cc9699" - integrity sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw== - dependencies: - "@sinonjs/commons" "^3.0.0" - "@sinonjs/fake-timers@^10.0.2": version "10.3.0" resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz#55fdff1ecab9f354019129daf4df0dd4d923ea66" @@ -1477,14 +1470,14 @@ dependencies: "@sinonjs/commons" "^3.0.0" -"@sinonjs/fake-timers@^13.0.1": +"@sinonjs/fake-timers@^13.0.1", "@sinonjs/fake-timers@^13.0.2": version "13.0.2" resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-13.0.2.tgz#3ffe88abb062067a580fdfba706ad00435a0f2a6" integrity sha512-4Bb+oqXZTSTZ1q27Izly9lv8B9dlV61CROxPiVtywwzv5SnytJqhvYe6FclHYuXml4cd1VHPo1zd5PmTeJozvA== dependencies: "@sinonjs/commons" "^3.0.1" -"@sinonjs/samsam@^8.0.0": +"@sinonjs/samsam@^8.0.1": version "8.0.2" resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-8.0.2.tgz#e4386bf668ff36c95949e55a38dc5f5892fc2689" integrity sha512-v46t/fwnhejRSFTGqbpn9u+LQ9xJDse10gNnPgAcxgdoCDMXj/G2asWAC/8Qs+BAZDicX+MNZouXT1A7c83kVw== @@ -3069,10 +3062,10 @@ diff-sequences@^29.6.3: resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921" integrity sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q== -diff@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-5.2.0.tgz#26ded047cd1179b78b9537d5ef725503ce1ae531" - integrity sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A== +diff@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-7.0.0.tgz#3fb34d387cd76d803f6eebea67b921dab0182a9a" + integrity sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw== docopt@~0.6.2: version "0.6.2" @@ -5759,7 +5752,7 @@ neo-async@^2.6.2: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -nise@^6.0.0: +nise@^6.1.1: version "6.1.1" resolved "https://registry.yarnpkg.com/nise/-/nise-6.1.1.tgz#78ea93cc49be122e44cb7c8fdf597b0e8778b64a" integrity sha512-aMSAzLVY7LyeM60gvBS423nBmIPP+Wy7St7hsb+8/fc1HmeoHJfLO8CKse4u3BtOZvQLJghYPI2i/1WZrEj5/g== @@ -6885,17 +6878,17 @@ simple-update-notifier@^2.0.0: dependencies: semver "^7.5.3" -sinon@^18.0.0: - version "18.0.1" - resolved "https://registry.yarnpkg.com/sinon/-/sinon-18.0.1.tgz#464334cdfea2cddc5eda9a4ea7e2e3f0c7a91c5e" - integrity sha512-a2N2TDY1uGviajJ6r4D1CyRAkzE9NNVlYOV1wX5xQDuAk0ONgzgRl0EjCQuRCPxOwp13ghsMwt9Gdldujs39qw== +sinon@^19.0.2: + version "19.0.2" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-19.0.2.tgz#944cf771d22236aa84fc1ab70ce5bffc3a215dad" + integrity sha512-euuToqM+PjO4UgXeLETsfQiuoyPXlqFezr6YZDFwHR3t4qaX0fZUe1MfPMznTL5f8BWrVS89KduLdMUsxFCO6g== dependencies: "@sinonjs/commons" "^3.0.1" - "@sinonjs/fake-timers" "11.2.2" - "@sinonjs/samsam" "^8.0.0" - diff "^5.2.0" - nise "^6.0.0" - supports-color "^7" + "@sinonjs/fake-timers" "^13.0.2" + "@sinonjs/samsam" "^8.0.1" + diff "^7.0.0" + nise "^6.1.1" + supports-color "^7.2.0" sisteransi@^1.0.5: version "1.0.5" @@ -7182,7 +7175,7 @@ supports-color@^5.3.0, supports-color@^5.5.0: dependencies: has-flag "^3.0.0" -supports-color@^7, supports-color@^7.1.0: +supports-color@^7.1.0, supports-color@^7.2.0: version "7.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== From 9d64ce0bb969877f2e264baa1b8ba6f4592a3c5e Mon Sep 17 00:00:00 2001 From: Hangjit Rai Date: Sat, 12 Oct 2024 18:01:05 +1100 Subject: [PATCH 2/2] cleanup --- .husky/common.sh | 2 +- .husky/prepare-commit-msg | 43 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/.husky/common.sh b/.husky/common.sh index b821568..35bc37b 100644 --- a/.husky/common.sh +++ b/.husky/common.sh @@ -1,5 +1,5 @@ command_exists () { - command -v "$1" >/dev/null 2>&1 + command -v "$1" > /dev/null 2>&1 & } # Windows 10, Git Bash and Yarn workaround diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg index ea53e71..0a075bc 100755 --- a/.husky/prepare-commit-msg +++ b/.husky/prepare-commit-msg @@ -3,5 +3,44 @@ . "$(dirname "$0")/_/husky.sh" . "$(dirname "$0")/common.sh" -# Bash sets the BASH environment variable, so if it is not set, then we -# are running in a different shell, so manually run ourselves in BASH. +# # Bash sets the BASH environment variable, so if it is not set, then we +# # are running in a different shell, so manually run ourselves in BASH. +# if [ -z "${BASH:-}" ]; then +# exec bash "$0" "$@" +# fi +# +# # Include any branches for which you wish to disable this script +# if [ -z "$BRANCHES_TO_SKIP" ]; then +# BRANCHES_TO_SKIP=(master develop staging test) +# fi +# +# # Get the current branch name and check if it is excluded +# BRANCH_NAME=$(git symbolic-ref --short HEAD) +# +# # Remove 'feature/' from the branch name for branch names like +# # feature/PEN-23 so the BRANCH_NAME will be 'PEN-23' only +# BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/feature\///gI') +# BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$") +# +# # Remove 'bugfix/' from the branch name for branch names like +# # bugfix/PEN-23 so the BRANCH_NAME will be 'PEN-23' only +# BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/bugfix\///gI') +# BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$") +# +# # Trim it down to get the parts we're interested in +# TRIMMED=$(echo $BRANCH_NAME | sed -e 's:^\([^-]*-[^-]*\)-.*:\1:' -e \ +# 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/') +# +# # Replace all the instances of the current branch name in the commit message - for amending commits +# sed -i "s/$BRANCH_NAME\s/ /g" $1 +# +# # Delete BOTH leading and trailing whitespace from each line +# sed -i 's/^[ \t]*//;s/[ \t]*$//' $1 +# +# # If it isn't excluded, prepend the trimmed branch identifier to the given message +# if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]]; then +# sed -i.bak -e "1s/^/$TRIMMED /" $1 +# fi +# +# # Capitalise the first letter of each word +# sed -i "s/\( \|^\|-\)\(.\)/\1\u\2/g" $1