Skip to content

Commit

Permalink
commitlint: use When enum
Browse files Browse the repository at this point in the history
  • Loading branch information
tehraninasab committed Feb 25, 2023
1 parent cae2cdc commit 50de12e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = {
header: any;
body: any;
},
when: string
when: When
) => {
Helpers.assertWhen(when);

Expand Down
3 changes: 2 additions & 1 deletion commitlint/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ export abstract class Helpers {
return text as string;
}

public static assertWhen(when: string) {
public static assertWhen(when: When) {
if (when !== When.Never && when !== When.Always) {
throw new Error(
'Variable "when" should be either "never" or "always"'
);
}
return when
}

public static assertCharacter(letter: string) {
Expand Down
4 changes: 2 additions & 2 deletions commitlint/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { abbr } from "./abbreviations";
import { Helpers } from "./helpers";
import { Helpers, When } from "./helpers";

export abstract class Plugins {
public static bodyProse(rawStr: string) {
Expand Down Expand Up @@ -265,7 +265,7 @@ export abstract class Plugins {
public static defaultRevertMessage(
headerStr: string,
bodyStr: string | null,
when: string
when: When
) {
let offence = false;
let isRevertCommitMessage = headerStr.toLowerCase().includes("revert");
Expand Down

0 comments on commit 50de12e

Please sign in to comment.