Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commitlint: subject-full-stop integration tests #70

Merged
merged 5 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 16 additions & 58 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,33 @@ module.exports = {
// * Detect reverts which have not been elaborated.
// * Reject some stupid obvious words: change, update, modify (if first word after colon, error; otherwise warning).
// * Think of how to reject this shitty commit message: https://github.com/nblockchain/NOnion/pull/34/commits/9ffcb373a1147ed1c729e8aca4ffd30467255594
// * Title should not have dot at the end.
// * Workflow: detect if wip commit in a branch not named "wip/*" or whose name contains "squashed".
// * Detect if commit hash mention in commit msg actually exists in repo.
// * Detect scope(sub-scope) in the title that doesn't include scope part (e.g., writing (bar) instead of foo(bar))

{
rules: {
"body-prose": ({ raw }: { raw: any }) => {
let rawUncastedStr = Helpers.convertAnyToString(raw, "raw");
let rawStr = Helpers.assertNotNull(
rawUncastedStr,
Helpers.convertAnyToString(raw, "raw"),
notNullStringErrorMessage("raw")
).trim();
);

return Plugins.bodyProse(rawStr);
},

"commit-hash-alone": ({ raw }: { raw: any }) => {
let rawUncastedStr = Helpers.convertAnyToString(raw, "raw");
let rawStr = Helpers.assertNotNull(
rawUncastedStr,
Helpers.convertAnyToString(raw, "raw"),
notNullStringErrorMessage("raw")
);

return Plugins.commitHashAlone(rawStr);
},

"empty-wip": ({ header }: { header: any }) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

Expand All @@ -99,12 +92,8 @@ module.exports = {
_: any,
maxLineLength: number
) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

Expand All @@ -130,71 +119,53 @@ module.exports = {
}: {
header: any;
}) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

return Plugins.preferSlashOverBackslash(headerStr);
},

"proper-issue-refs": ({ raw }: { raw: any }) => {
let rawUncastedStr = Helpers.convertAnyToString(raw, "raw");
let rawStr = Helpers.assertNotNull(
rawUncastedStr,
Helpers.convertAnyToString(raw, "raw"),
notNullStringErrorMessage("raw")
).trim();
);

return Plugins.properIssueRefs(rawStr);
},

"title-uppercase": ({ header }: { header: any }) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

return Plugins.titleUppercase(headerStr);
},

"too-many-spaces": ({ raw }: { raw: any }) => {
let rawUncastedStr = Helpers.convertAnyToString(raw, "raw");
let rawStr = Helpers.assertNotNull(
rawUncastedStr,
Helpers.convertAnyToString(raw, "raw"),
notNullStringErrorMessage("raw")
);

return Plugins.tooManySpaces(rawStr);
},

"type-space-after-colon": ({ header }: { header: any }) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

return Plugins.typeSpaceAfterColon(headerStr);
},

"type-with-square-brackets": ({ header }: { header: any }) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

Expand All @@ -203,24 +174,16 @@ module.exports = {

// NOTE: we use 'header' instead of 'subject' as a workaround to this bug: https://github.com/conventional-changelog/commitlint/issues/3404
"subject-lowercase": ({ header }: { header: any }) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);
return Plugins.subjectLowercase(headerStr);
},

"type-space-after-comma": ({ header }: { header: any }) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

Expand All @@ -240,22 +203,17 @@ module.exports = {
},

"trailing-whitespace": ({ raw }: { raw: any }) => {
let rawUncastedStr = Helpers.convertAnyToString(raw, "raw");
let rawStr = Helpers.assertNotNull(
rawUncastedStr,
Helpers.convertAnyToString(raw, "raw"),
notNullStringErrorMessage("raw")
);

return Plugins.trailingWhitespace(rawStr);
},

"type-space-before-paren": ({ header }: { header: any }) => {
let headerUncastedStr = Helpers.convertAnyToString(
header,
"header"
);
let headerStr = Helpers.assertNotNull(
headerUncastedStr,
Helpers.convertAnyToString(header, "header"),
notNullStringErrorMessage("header")
);

Expand Down
3 changes: 3 additions & 0 deletions commitlint/abbreviations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export let abbr = {
"convert": "conv",
"coordinate": "coord",
"coordinates": "coords",
"copy": "cp",
"csharp": "C#",
"c-sharp": "C#",
"database": "DB",
Expand Down Expand Up @@ -154,6 +155,7 @@ export let abbr = {
"interfaces": "ifaces",
"issue": "bug",
"issues": "bugs",
"javascript": "JS",
"language": "lang",
"languages": "langs",
"length": "len",
Expand Down Expand Up @@ -279,6 +281,7 @@ export let abbr = {
"values": "vals",
"variable": "var",
"variables": "vars",
"webassembly": "WebAsm",
"yes/no": "y/n",
"zero": "0",
"zeroes": "0s",
Expand Down
26 changes: 26 additions & 0 deletions commitlint/integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let cp = require("child_process");

function runCommitLintOnMsg(inputMsg: string) {
return cp.spawnSync("npx", ["commitlint", "--verbose"], {
input: inputMsg,
});
}

test("body-leading-blank1", () => {
let commitMsgWithoutEmptySecondLine =
"foo: this is only a title" + "\n" + "Bar baz.";
let bodyLeadingBlank1 = runCommitLintOnMsg(commitMsgWithoutEmptySecondLine);
expect(bodyLeadingBlank1.status).not.toBe(0);
});

test("subject-full-stop1", () => {
let commitMsgWithEndingDotInTitle = "foo/bar: bla bla blah.";
let subjectFullStop1 = runCommitLintOnMsg(commitMsgWithEndingDotInTitle);
expect(subjectFullStop1.status).not.toBe(0);
});

test("subject-full-stop2", () => {
let commitMsgWithoutEndingDotInTitle = "foo/bar: bla bla blah";
let subjectFullStop2 = runCommitLintOnMsg(commitMsgWithoutEndingDotInTitle);
expect(subjectFullStop2.status).toBe(0);
});
7 changes: 0 additions & 7 deletions commitlint/plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ function runCommitLintOnMsg(inputMsg: string) {
return spawnSync("npx", ["commitlint", "--verbose"], { input: inputMsg });
}

test("body-leading-blank1", () => {
let commitMsgWithoutEmptySecondLine =
"foo: this is only a title" + "\n" + "Bar baz.";
let bodyLeadingBlank1 = runCommitLintOnMsg(commitMsgWithoutEmptySecondLine);
expect(bodyLeadingBlank1.status).not.toBe(0);
});

test("body-prose1", () => {
let commitMsgWithLowercaseBodyStart =
"foo: this is only a title" + "\n\n" + "bla blah bla.";
Expand Down
2 changes: 2 additions & 0 deletions commitlint/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export abstract class Plugins {
public static bodyProse(rawStr: string) {
let offence = false;

rawStr = rawStr.trim();
let lineBreakIndex = rawStr.indexOf("\n");

if (lineBreakIndex >= 0) {
Expand Down Expand Up @@ -243,6 +244,7 @@ export abstract class Plugins {
public static properIssueRefs(rawStr: string) {
let offence = false;

rawStr = rawStr.trim();
let lineBreakIndex = rawStr.indexOf("\n");

if (lineBreakIndex >= 0) {
Expand Down