fix: regex

This commit is contained in:
Adrian Smijulj 2020-06-11 13:03:26 +02:00
parent 2f1b82c9db
commit 10dafee2e8
3 changed files with 6 additions and 4 deletions

4
dist/main/index.js vendored
View file

@ -453,8 +453,8 @@ const isValidCommitMessage = (message, availableTypes = DEFAULT_COMMIT_TYPES) =>
let [possiblyValidCommitType] = message.split(":");
possiblyValidCommitType = possiblyValidCommitType.toLowerCase();
// Let's remove scope if present.
if (possiblyValidCommitType.match(/\([a-z]*?\)/)) {
possiblyValidCommitType = possiblyValidCommitType.replace(/\([a-z]*?\)/, "");
if (possiblyValidCommitType.match(/\(\S*?\)/)) {
possiblyValidCommitType = possiblyValidCommitType.replace(/\(\S*?\)/, "");
}
possiblyValidCommitType = possiblyValidCommitType
.replace(/\s/g, "") // Remove all whitespace

View file

@ -1,6 +1,7 @@
import isValidCommitMessage from "../isValidCommitMesage";
test("should be able to correctly validate the commit message", () => {
expect(isValidCommitMessage("chore(nice-one): doing this right")).toBe(true);
expect(isValidCommitMessage("fix: menu must open on shortcut press")).toBe(true);
expect(isValidCommitMessage("something: should not work")).toBe(false);
expect(isValidCommitMessage("fixes something")).toBe(false);
@ -9,4 +10,5 @@ test("should be able to correctly validate the commit message", () => {
expect(isValidCommitMessage("🚧 fix(menus): menu must open on shortcut press")).toBe(true);
expect(isValidCommitMessage("🚧 fixing something")).toBe(false);
expect(isValidCommitMessage("🚧 something: should not work")).toBe(false);
expect(isValidCommitMessage("chorz: 123")).toBe(false);
});

View file

@ -18,8 +18,8 @@ const isValidCommitMessage = (message, availableTypes = DEFAULT_COMMIT_TYPES): b
possiblyValidCommitType = possiblyValidCommitType.toLowerCase();
// Let's remove scope if present.
if (possiblyValidCommitType.match(/\([a-z]*?\)/)) {
possiblyValidCommitType = possiblyValidCommitType.replace(/\([a-z]*?\)/, "");
if (possiblyValidCommitType.match(/\(\S*?\)/)) {
possiblyValidCommitType = possiblyValidCommitType.replace(/\(\S*?\)/, "");
}
possiblyValidCommitType = possiblyValidCommitType