Skip to content

Commit

Permalink
Fixed nums regex match (#268)
Browse files Browse the repository at this point in the history
* cleanup

* cleanup
  • Loading branch information
hrai authored Oct 12, 2024
1 parent 046187a commit ff542e1
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .husky/common.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
82 changes: 41 additions & 41 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +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.
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
# # 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <war>? 1')).toBe(false);

expect(utils.shouldCapitalise('?')).toBe(true);
expect(utils.shouldCapitalise('!')).toBe(true);
Expand All @@ -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', () => {
Expand Down
41 changes: 17 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1463,28 +1463,21 @@
dependencies:
type-detect "4.0.8"

"@sinonjs/[email protected]":
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"
integrity sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==
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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit ff542e1

Please sign in to comment.